asp.net mvc - Jquery to reset dropdownlist's selected index is not working -


i have check box , dropdownlist on mvc4 razor page

when uncheck check box ,i need reset dropdownlist's selection 0

$("#chkprocess").click(function (event) {         //on-click code goes in here.         var chkprocess = $(this);         if (chkprocess.is(':checked')) {            //do process         } else {             $('#locationselectlist').val('0');             alert("" + $("#locationselectlist option:selected").val());          }     }); 

when uncheck checkbox ,i getting alert showing selected index=0,but on screen not reflecting change. need dropdown reset selection on screen .why seeing behaviour , doing wrong here?

i have these jquery files referenced on _layout page

    <script src="@url.content("~/scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/jquery.treeview.js")" type="text/javascript"></script>      <script src="@url.content("~/scripts/jquery.ui.selectmenu.js")" type="text/javascript"></script>      <script src="@url.content("~/scripts/modernizr-1.7.min.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 

i tried these

$('#locationselectlist').attr('selectedindex', '0');  $('#locationselectlist').val('0'); 

but can see in alert message resetting selected index,but not getting same reflected on page.

check out link.

http://jsfiddle.net/sheeban/wgamw/2/

html

<input type="checkbox" id="chkprocess"/> <select id="locationselectlist">     <option value="chennai">chennai</option>     <option value="bangalore">bangalore</option> </select> 

js

$(function() { $("#chkprocess").click(function (event) {     if(!$(this).is(':checked')) {          $('#locationselectlist').prop('selectedindex',0);     }   }); }); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -