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!

CREATING A DROPDOWN MENU

Status
Not open for further replies.

FOXPROG

Programmer
Jan 14, 2001
51
US
I know you can access and control dropdown menus , list boxes etc from javascript but I was wondering can you create a dropdown menu completely from javascript and if so how?
 
<script>
document.write(&quot;<select>&quot;);
document.write(&quot;<option>one&quot;);
document.write(&quot;<option>two&quot;);
document.write(&quot;<option>three&quot;);
document.write(&quot;</select>&quot;);
</script>
admin@onpntwebdesigns.com
 
Thanks! How can I get it to not clear the form so my other dropdowns don't disappear?
 
Instead of using document.write, you could use document.writeln (that's as in write line). I'm not sure about browser problems with writeln, but it's been in IE for ages.

Hope that helps.
 
I think what FOXPROG requested is something similar to this:

<script>
texts = new Array('one', 'two', 'three');
values = new Array(1, 2, 3);
var total_options = 3;

document.write('<select name=thelist>');
for (n=0; n<total_options; n++)
{
thelist.options[n] = new Option();
thelist.options[n].value = values[n];
thelist.options[n].text = texts[n];
}
document.write('</select>');
</script>

Warning: I wrote this on the fly, so the script can require soem debugging.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top