Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging it with jQuery select doesn't show selected option
    primarykey
    data
    text
    <p>I have hidden form with a few select fields and some input fields. Click on button should show that form and set some values in the fields. The input fields are filled with given values but I have problem with select fields.</p> <p>Using this code:</p> <pre><code>$("#form select[name=user]").val(value); </code></pre> <p>option with that value gets attribute "selected" (checked in Firebug) but select field still shows "Choose" (initial) option.</p> <p>I tried to do focus and blur after setting value but that didn't work either.</p> <p>Any suggestions?</p> <hr> <p>This is pretty much the standard form:</p> <pre><code>&lt;form action="#" id="form" class="fix"&gt; &lt;div class="holder"&gt; &lt;label&gt;User:&lt;/label&gt; &lt;select name="user" class="styled"&gt; &lt;option value="0" selected&gt;Choose&lt;/option&gt; &lt;option value="1"&gt;User 1&lt;/option&gt; &lt;option value="2"&gt;User 2&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>And by calling jQuery statement:</p> <pre><code>$("#form select[name=user]").val('2'); $("#form").show(); </code></pre> <p>I get this in Firebug:</p> <pre><code>&lt;form action="#" id="form" class="fix" style="display:none"&gt; &lt;div class="holder"&gt; &lt;label&gt;User:&lt;/label&gt; &lt;select name="user" class="styled"&gt; &lt;option value="0"&gt;Choose&lt;/option&gt; &lt;option value="1"&gt;User 1&lt;/option&gt; &lt;option value="2" selected&gt;User 2&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>but the text is select stays "Choose". If I submit form, the value is correctly passed.</p> <p>Than if I reset the form and select some option the text of selected option is shown properly. That's what's weird to me.</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.
    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