Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdown (selection) in MVC PartialView does not update text after changing value by jQuery
    text
    copied!<p>I have a MVC 2 / jQuery mobile application. </p> <p>On my main view I have a list that is sortable. The sort works by url parameter <code>sortorder</code>. the dropdown with which you can change the sorting is in a partial view that looks like this:</p> <pre><code>&lt;div class="ui-select"&gt; &lt;select name="sortSelect" id="sortSelect" data-mini="true"&gt; &lt;option value="opt1"&gt;Option 1&lt;/option&gt; &lt;option value="opt2"&gt;Option 2&lt;/option&gt; &lt;option value="opt3"&gt;Option 3&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; </code></pre> <p>Then I have a jQuery that checks whether the dropdown is changed. On change it adds or changes url <code>sort</code> parameter with new dropdown value and redirects to new url:</p> <pre><code>$(document).ready(function () { $('#sortSelect').change(function () { var sortOrder = $('#sortSelect').val(); var url = document.URL; if (url.indexOf("sortorder=") &gt; -1) url = url.replace(/sortorder=[^&amp;]+/, "sortorder=" + sortOrder); else url = url + "&amp;sortorder=" + sortOrder; window.location.replace(url); }); }); </code></pre> <p>As there are a few other parameters before the sortorder it is ok that is added with &amp;.</p> <p>To set the correct value from the url when the page is newly loaded I have following jQuery (function gup reads value from url):</p> <pre><code>$('#sortSelect').ready(function () { var sortorder = gup('sortorder'); if (sortorder != '') $('#sortSelect').val(sortorder); } </code></pre> <p>There is the problem: if I load the site and change the <code>sortorder</code> by dropdown, everything works so far. The page is newly loaded with new url parameter and newly sorted list. even the dropdown value is set correctly (I checked this by <code>alert($('#sortSelect').val()</code>, but the dropdown text is the old one. If I press F5 the site refreshes, and the dropdown has its correct text...</p> <p>Any ideas how i can solve the problem? Or what is the problem at all?</p>
 

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