john john - 3 months ago 21
Javascript Question

I cant find the selected value in my asp Dropdown

I would like to show a div depending on the selection in the dropdown.
I am filling the dropdown with 2 values from a sharePoint service
They are Inside or Outside. When the user selects Inside I would like to show the div. I am however unable to select the selected value. How do I do this in jQuery?

<asp:DropDownList runat="server" id="urlOptions">
<asp:ListItem Value="" Text="Select Answer"></asp:ListItem>




<script type="text/javascript" >
$(function () {
$("button").on("click", function () {
if ($("#urlOptions").val() == "Inside") {
$("#div1").show();
}
else {
alert("something is wong");
}
return false;
});
});



Answer
 $(function () {
     $("button").on("click", function () {
         if ($("#<%= urlOptions.ClientID %>").val() == "Inside") {
                $("#div1").show();
         }
         else   {
             alert("something is wong");
         }
         return false;
     });
 });

urlOptions is server ID while actual rendered HTML id is different. But you can find out it by using urlOptions.ClientID property.