0

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;
     });
 });

john
  • 15
  • 4
  • oh god, stop using asp.net. But you have to get the client side id of the element to query it in javascript http://stackoverflow.com/questions/6776789/find-out-client-side-id-of-html-element-created-by-net – QBM5 Aug 19 '16 at 20:16

1 Answers1

1
 $(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.

serhiyb
  • 4,753
  • 2
  • 15
  • 24