|
I am trying to get the value of a dynamically created select box. The script I am using to get the value is :
<script language = "javascript" >
function extract() {
i=document.RESULT_FORM.TOPIC_TYPE.selectedIndex;
var x = document.RESULT_FORM.TOPIC_TYPE.options.value;
}
</script>
The script I used to create the dynamic select box is :
<select name="TOPIC_TYPE" size="1"
style="background-color:#ffffcc;">
<option>ALL</option>
<SCRIPT Language="JavaScript">
var buildinglist=document.RESULT_FORM.BLDGLIST.value
var bldgarray=buildinglist.split(" ");
var bldglist_counter=document.RESULT_FORM.BLDGLIST_CNT.value
for (var i=0; i < bldglist_counter; i++)
document.write("<OPTION>") +
document.write(bldgarray) +
document.write("</OPTION>");
</SCRIPT>
By using an alert, I am able to see that the selectIndex value for i is correct. but when I use an alert for x, the value is empty. Any suggestions? Thanks!
Bill
<Added>
var x = document.RESULT_FORM.TOPIC_TYPE.options.value;
|
|
|
Simply remove ".options" from this line:
var x = document.RESULT_FORM.TOPIC_TYPE.options.value; |
|
This code shows the working solution.
<script language = "javascript" >
function extract() {
i=document.RESULT_FORM.TOPIC_TYPE.selectedIndex;
alert(i);
var x = document.RESULT_FORM.TOPIC_TYPE.value;
alert(x);
}
</script>
<form name="RESULT_FORM">
<select name="TOPIC_TYPE">
<option value="value 1">Option 1</option>
<option value="value 2">Option 2</option>
<option value="value 3">Option 3</option>
</select>
<p>
<input type=button value="Test" onclick=extract()>
</form>
|
|
|
|
|
|
|
Sure enough, your code did work. What I was doing wrong was that I did not define a value for the option tags. I just had <OPTION>option</option>. Thanks for your help!
Oh, thanks for the details on the seminar.
Bill
|
|
|
|
|
|
|
|