Add Options to a Combo Box Using JavaScript

From SmartWiki
Revision as of 14:12, 31 July 2009 by Cameron (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You can use a JavaScript function to modify the options available in a pull-down box on the page.

The following example adds a new blank selection at the top of the starthour field at Level 2:

try{
 document.forms[0].starthour.add(new Option("", "", true, true), document.forms[0].starthour.options[0]) 
}
catch(e){ //in IE, try the below version instead of add()
 document.forms[0].starthour.add(new Option("", "", true, true), 0)
}