Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update Select Option drop down menu with jQuery?
    primarykey
    data
    text
    <p>Im using this CODE below to create a GET/Import button on my form. I want to import NAME and AGE for my useres.</p> <p>This is my jQuery script to get values:</p> <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('.button').click(function() { $.get('values.php', function(data) { result = $.parseJSON(data); $("input[name='nick_name']").val(result.avaname); $("option[name='age']").val(result.tavaage); }); }); }); &lt;/script&gt; </code></pre> <p>This is my form with "<strong>input field</strong> for <code>name</code>" and "<strong>select option menu</strong> for <code>age</code>":</p> <pre><code>&lt;tr&gt; &lt;td&gt;&lt;label&gt;Name &lt;span&gt;(nickname)&lt;/span&gt;&lt;/label&gt;&lt;input type="text" value="&lt;? echo $nick_name;?&gt;" id="nick_name" class="" name="nick_name" /&gt;&lt;/td&gt; &lt;td&gt;&lt;label&gt;Age&lt;/label&gt;&lt;select id="age" class="" name="age" &gt;&lt;option value="&lt;? echo $age; ?&gt;" &gt;&lt;? echo $age; ?&gt;&lt;/option&gt; &lt;option value="18" &gt;18&lt;/option&gt; &lt;option value="19" &gt;19&lt;/option&gt; &lt;option value="20" &gt;20&lt;/option&gt; &lt;option value="21" &gt;21&lt;/option&gt; &lt;option value="22" &gt;22&lt;/option&gt; &lt;option value="23" &gt;23&lt;/option&gt; &lt;option value="24" &gt;24&lt;/option&gt; &lt;option value="25" &gt;25&lt;/option&gt; &lt;option value="26" &gt;26&lt;/option&gt; &lt;option value="27" &gt;27&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;input class="button" type="button" value="Get/Import" /&gt; </code></pre> <p><strong>My problem is</strong>: When I press this button then the input field for <code>name</code> updates and shows the <code>name</code> as expected but the <code>age</code> select option is still empty?</p> <p>My question is: How can I updates/add option values for my select menu for <code>age</code>? (I know in my jQuery script LINE NR 8 is incorrect, but thats what I have tried)</p> <p>All help will be highly appreciated :D </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