jQuery changing SELECT not working properly -


(using jquery mobile) have reset button needs reset of dropdown boxes selectedindex equal 0. believe index zero, value shown on select box not correct. keeps same value.

heres jsfiddle

for example: select 'unit2' , click reset. click ok. value shown on select box 'unit2' whereas should '--units--'

html

<div data-role="fieldcontain" class='seltype' id='xmep' >   <select id="dmep" data-mini='true'>     <option value="0">--units--</option>     <option value='1'>unit1</option>     <option value='0.01'>unit2</option>     <option value='10'>unit3</option>   </select> </div> 

.

.

jquery

$(document).ready(function() {   $('#rstbtn').click(function() {      var answer = confirm('click ok set selectindex equal 0');          if (answer == false) {             return;         } else {             $('select').prop('selectedindex', 0);         }   });  }); 

you need refresh select menu using .selectmenu('refresh',true).

demo

$(document).ready(function() {   $('#rstbtn').on('click', function() {      if (confirm('click ok set selectindex equal 0')) {          $('#dmep').val(0).selectmenu('refresh',true);       }   }); }); 

this more precise

  $('#dmep').find('option[value="0"]')   .prop('selected', true).addback()    .selectmenu('refresh', true); 

or

   $('#dmep').prop('selectedindex', 0)    .selectmenu('refresh', true); 

Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -