matala
asked on
Can an <option> tag be dynamically modified?
Can the following be done:
An html page contains radio buttons and an option tag (combo box). If you click one of the radio buttons, a javascript is called that will modify the content (the pulldown options) in the option tag dynamically without reloading a new page. Can it be done? if so, what is the code (in JVScript or html) that will modify the content of the option dynamically.
An html page contains radio buttons and an option tag (combo box). If you click one of the radio buttons, a javascript is called that will modify the content (the pulldown options) in the option tag dynamically without reloading a new page. Can it be done? if so, what is the code (in JVScript or html) that will modify the content of the option dynamically.
The list has got to be filled with x empty options where x is the number of options that will ever be used.
Then, you dynamically assign text and value
<SELECT>
<OPTION>
<OPTION>
<OPTION>
</SELECT>
[...]
// A list
list.options[0].value = "soccer";
list.options[0].text = "Soccer";
list.options[1].value = "basketball";
list.options[1].text = "BasketBall;
list.options[2].value = "hockey";
list.options[3].text = "Hockey";
[...]
// Another list
list.options[0].value = "y";
list.options[0].text = "Yes";
list.options[1].value = "n";
list.options[1].text = "No";
list.options[2].value = ""; // Empty, or it will be "hockey"
list.options[3].text = ""; // Empty, or it will be "Hockey"
Martin
Then, you dynamically assign text and value
<SELECT>
<OPTION>
<OPTION>
<OPTION>
</SELECT>
[...]
// A list
list.options[0].value = "soccer";
list.options[0].text = "Soccer";
list.options[1].value = "basketball";
list.options[1].text = "BasketBall;
list.options[2].value = "hockey";
list.options[3].text = "Hockey";
[...]
// Another list
list.options[0].value = "y";
list.options[0].text = "Yes";
list.options[1].value = "n";
list.options[1].text = "No";
list.options[2].value = ""; // Empty, or it will be "hockey"
list.options[3].text = ""; // Empty, or it will be "Hockey"
Martin
When you do like PBall suggests you have to reload for the changes to be made.
Martin
Martin
Oops.
list.options[2].value = ...
list.options[3].text = ...
should of course be
list.options[2].value = ..
list.options[2].text = ...
Martin
list.options[2].value = ...
list.options[3].text = ...
should of course be
list.options[2].value = ..
list.options[2].text = ...
Martin
ASKER
Thanks, it works with netscape, but not with iexplorer. How can I make it work in both.
The error in iexplorer 4.0 is "...options is not an object"
The error in iexplorer 4.0 is "...options is not an object"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<select name=selAnswers>
<option value='a'>16 meters
<option value='b'>12 meters
<option value='c'>14 meters
<option value='d'>other
<script>
document.selAnswer.options
document.selAnswer.options
document.selAnswer.options
document.selAnswer.options
</script>
Hmm..I forgot how to delete the previous options tho, hmm...
anyone?