To change "master"s content using JavaScript, do the following:
1) Remove all options by setting the Options array's length to 0
document.myform.master.options.length=0
Doing the above instantly empties the select element, ready to be populated with new data.
2) Repopulate the select menu with new options (aka content), using the Option() constructor on each option:
document.myform.master.options[0]=new Option("Sports", "sportsvalue", true, false)
document.myform.master.options[1]=new Option("Music", "musicvalue", false, false)
document.myform.master.options[2]=new Option("Movies", "moviesvalue", false, false)
The select menu is now repopulated with 3 new entries ("Sports", "Music", and "Movies").
In case you're wondering, the Option() constructor supports the following four parameters,
the later two optional:
new Option(text, value, defaultSelected, selected)
Looping through and changing select element content
When repopulating a select element's content, you may want to use a loop instead of
changing each option one by one.
Furthermore, the total number of options may not be known in advance (such as 3 above),
so you need a dynamic way to add new options to select. In this case, use the below:
var master=document.myform.master
for (i=0; i