Reputation: 21907
Say I have these variables:
var value1 = '';
var textvalue1 = '';
...
How do I use jquery to set the values and text of a dropdown box from these variables?
<div id"lang">
<form name="languages" id="langSelector">
<select name="file" size="1" target="_blank">
<option value="VALUE">TEXT</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
</form></div>
Upvotes: 0
Views: 198
Reputation: 114437
$('#lang').find('option').eq(0).attr('value',0)
$('#lang').find('option').eq(0).attr('text','whatever')
adjust eq(0) to the position of the index you require.
Upvotes: 2
Reputation: 50982
$("option:eq(0)").val(textvalue1);
or you can use nt-child
instead of eq
Upvotes: 1