Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Web
Expertise: Intermediate
Mar 19, 1999



Application Security Testing: An Integral Part of DevOps

Dynamically Create Selection Box Options

You can create selection box options dynamically using JavaScript 3.0's Option object. The syntax for its constuctor is:
Option(text, value, [default selected], [selected])
Here is an example:

<form name=MyForm>
<script language = javascript>
function foo(){
    document.MyForm.select1.length=0;  //this clears the select box
    document.MyForm.select1.options[0] = new Option("<Select One>","0",true,true);
         for (var i=0; i < 20;i++)	{
	document.MyForm.select1.options[i+1] = new Option("Option" + i,"Value" + i);

<p><SELECT name="select1" style="HEIGHT: 22px; WIDTH: 340px">
<p><input type=button value="Populate" onclick="foo()">
William Wen
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date