Hi,
I have a .cshtml page which has some controls on top and table below.
Table is created with lots of if else condition and for that I want to access html controls value (dropdown selected value).
I am struggling with how to access dropdown list selected value in same .cshtml page.
so something like that ??
if(dropdown selected value == "4")
{
}

Uday DodiyaRank #239 · 10.3K reputationPosted Oct 2, 2024, 6:29 AM EDT
Hi,
You can go through folowing, html code
JS Code
function checkSelectedValue() { var dropdown = document.getElementById("myDropdown"); var selectedValue = dropdown.value; // Get the selected value // Conditional logic if (selectedValue == "4") { alert("Option 4 is selected!"); // You can place any additional logic here } else { alert("Option " + selectedValue + " is selected"); } }Jignesh KumarRank #91 · 22.9K reputationPosted Oct 1, 2024, 6:56 PM EDT
Hello,
You can create value for drop-down in html,
In JavaScript you can get selected value,
function getSelectedValue() { var select = document.getElementById("mySelect"); var selectedValue = select.options[select.selectedIndex].value; document.getElementById("result").innerText = "Selected Value: " + selectedValue; }