How to change the selected option in the selection by value menu in jQuery Mobile?

I need to change the selected option with a value coming from the database.

Here is the code:

// this code is in ondeviceready function. function onDeviceReady() { $("#txtgender2").val(data.data.gender).selectmenu("refresh"); } 

This code is somewhere in the div

 <div> <select name="txtgender2" id="txtgender2" data-role="slider"> <option value="Male" >Male</option> <option value="Female">Female</option> </select> </div> 

How to change the selected selectmenu option?

+4
source share
3 answers

If you want to update the selection menu using the data-role slider, you should use:

 $("#txtgender2").val(data.data.gender).slider("refresh"); 

instead:

 $("#txtgender2").val(data.data.gender).selectmenu("refresh"); 
0
source

If you want to update the selection menu using the data role slider, you should use:

 $("#txtgender2").val(data.data.gender).slider("refresh"); instead of: $("#txtgender2").val(data.data.gender).selectmenu("refresh"); 
0
source
 $("#txtgender2 option[value="'+data.data.gender+'"]").attr('selected', 'selected'); $('#txtgender2').selectmenu('refresh'); 
0
source

Source: https://habr.com/ru/post/1438827/


All Articles