Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamilcy Populate a <select>

Status
Not open for further replies.

zzfive03

Programmer
Jun 11, 2001
267
Hello,

I have a dynamicly loaded 2 dim array which I would like to populate into a <select> tag. I want it to do something like:

<option value=myArr[0][0]> myArr[0][1]</option>
<option value=myArr[1][0]> myArr[1][1]</option>
<option value=myArr[2][0]> myArr[2][1]</option>
<option value=myArr[3][0]> myArr[3][1]</option>

How can I access the text, and value of the option for the select to add new values?

Thank you in advance for any help. MH
 
like that :

var select = document.getElementById(&quot;selectname&quot;);
var newOption= document.createElement(&quot;OPTION&quot;);
select.options.add(newOption);
newOption.value=&quot;YOUR VALUE&quot;;
newOption.innerText=&quot;YOUR TEXT&quot;;


...
<select name=&quot;selectname&quot;></select>


good luck!
 
...or :

var option = document.getElementById(&quot;option1name&quot;);
option.value = X;
option.innerText = Y;


<select name=&quot;selectname&quot;>
<option name=&quot;option1name&quot;></option>
...
</select>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top