<html>
<head>
<title>Add or Remove Options on a form Select Field</title>
<script>
function buildSelect(x) {
if (x == "12") {
/* set choices 1 and 2 */
option0 = new Option(" Please Select ",0)
option1 = new Option("Value 1",1)
option2 = new Option("Value 2",2)
// write them
document.form1.fieldB.options[0] = option0
document.form1.fieldB.options[1] = option1
document.form1.fieldB.options[2] = option2
return;
}
if (x == "34") {
/* set choices 3 and 4 */
option0 = new Option(" Please Select ",0)
option1 = new Option("Value 3",1)
option2 = new Option("Value 4",2)
// write them
document.form1.fieldB.options[0] = option0
document.form1.fieldB.options[1] = option1
document.form1.fieldB.options[2] = option2
return;
}
if (x == "1234") {
/* set choices 1,2, 3, and 4 */
option0 = new Option(" Please Select ",0)
option1 = new Option("Value 1",1)
option2 = new Option("Value 2",2)
option3 = new Option("Value 3",3)
option4 = new Option("Value 4",4)
// write them
document.form1.fieldB.options[0] = option0
document.form1.fieldB.options[1] = option1
document.form1.fieldB.options[2] = option2
document.form1.fieldB.options[3] = option3
document.form1.fieldB.options[4] = option4
return;
}
if (x == "00") {
/* set choices to none */
option0 = new Option(" None ",0)
option1 = new Option("",1)
option2 = new Option("",2)
option3 = new Option("",3)
option4 = new Option("",4)
// write them
document.form1.fieldB.options[0] = option0
document.form1.fieldB.options[1] = option1
document.form1.fieldB.options[2] = option2
document.form1.fieldB.options[3] = option3
document.form1.fieldB.options[4] = option4
return;
}
}
</script>
</head>
<body>
<form name="form1">
<select name="fieldB">
<option size="15"> Select from below </option>
</select>
<br>
<input type="radio" name="choice" onclick="buildSelect(12)">Add choices 1 and 2<br>
<input type="radio" name="choice" onclick="buildSelect(34)">Add choices 3 and 4<br>
<input type="radio" name="choice" onclick="buildSelect(1234)"> Add all choices<br>
<input type="radio" name="choice" onclick="buildSelect(00)">Clear all choices
</form>
</body>
</html>