{"id":7993,"date":"2012-09-23T23:55:52","date_gmt":"2012-09-23T18:25:52","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=7993"},"modified":"2012-09-23T23:55:52","modified_gmt":"2012-09-23T18:25:52","slug":"dynamically-changing-select-value-of-jquery-mobile-select-box","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/dynamically-changing-select-value-of-jquery-mobile-select-box\/","title":{"rendered":"Dynamically changing select value of jQuery Mobile select box"},"content":{"rendered":"<p>jQuery mobile gives you a very beautiful UI which is compatible with all popular mobile device platforms and i must say its very easy to learn as well.<br \/>\nIt gives you a very nice select menu instead of typical select box that we see on our web site, for this we just need to add attribute <strong>&#8220;data-native-menu&#8221;<\/strong> in our select and we are done, e.g;<br \/>\n[java]<br \/>\n&lt;select name=&quot;reminderSettings&quot; id=&quot;reminderSettings&quot; data-native-menu=&quot;false&quot;&gt;<br \/>\n&lt;option value=&quot;1&quot; selected=&quot;selected&quot;&gt;1 day before&lt;\/option&gt;<br \/>\n&lt;option value=&quot;2&quot;&gt;2 days before&lt;\/option&gt;<br \/>\n&lt;option value=&quot;3&quot;&gt;3 days before&lt;\/option&gt;<br \/>\n&lt;option value=&quot;5&quot;&gt;5 days before&lt;\/option&gt;<br \/>\n&lt;\/select&gt;<br \/>\n[\/java]<\/p>\n<p>But the problem occurs when we need to change the selected value dynamically. Usually we write the following code to change the selected values of select box.<br \/>\n[java]<br \/>\nfunction setOptionValue(value){<br \/>\n  var reminderSettings = $(&quot;#reminderSettings&quot;);<br \/>\n  reminderSettings.val(value).attr(&#8216;selected&#8217;, true).siblings(&#8216;option&#8217;).removeAttr(&#8216;selected&#8217;);<br \/>\n}<br \/>\n[\/java]<br \/>\nIt will definitely change the selected value but the UI will not reflect it, to reflect this on the UI as well we need to refresh our select box.<br \/>\n[java]<br \/>\n    reminderSettings.selectmenu(&quot;refresh&quot;, true);<br \/>\n[\/java] <\/p>\n<p>We need to add the above line after changing our select value and its done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jQuery mobile gives you a very beautiful UI which is compatible with all popular mobile device platforms and i must say its very easy to learn as well. It gives you a very nice select menu instead of typical select box that we see on our web site, for this we just need to add [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[1],"tags":[970,1013,1014],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7993"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=7993"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7993\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=7993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=7993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=7993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}