Note that there are some explanatory texts on larger screens.

plurals
  1. POManually triggering the styling on a jQuery mobile select list
    primarykey
    data
    text
    <p>I'm building a select list with an Ajax call that is triggered when another select list is changed.</p> <p>The page loads correctly with the jQuery styling, but when I replace my ajax container with the new div I can't get jQuery mobile to format it. This means that it reverts to the native select list format.</p> <p>I have tried what is suggested in the <a href="http://jquerymobile.com/demos/1.0a4/docs/forms/forms-selects.html" rel="nofollow" title="Form Selects">JQM documentation</a>:</p> <pre><code>var myselect = $("select#foo"); myselect[0].selectedIndex = 3; myselect.selectmenu("refresh"); </code></pre> <p>but that does not work. My page initially loads with this:</p> <pre><code>&lt;div id="ajax-destination"&gt; &lt;select id="destinationAirport" data-native-menu="false"&gt; &lt;option value="-- Please Select --" data-placeholder="true"&gt;-- Please Select --&lt;/option&gt; &lt;/select&gt; </code></pre> <p></p> <p>and this is my jQuery code wrapped in the change function of the other select list.</p> <pre><code>$('#ajax-destination').empty(); $.post(url, { departureAirport : departureAirport }, function(data) { $('#ajax-destination').append(data); var myselect = $("#destinationAirport"); myselect[0].selectedIndex = 1; myselect.selectmenu("refresh"); }); </code></pre> <p>The only other way I can think to do this is to return a JSON array via Ajax and use that to add the options to the select list, but I would prefer to just send formatted HTML because it's simpler to follow.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload