A
arno
Hello,
I have a form with a dropdown list. Now, I would like to know in javascript
what value was selected but I cannot figure that out.
Here are my two scripts that do not work, the first is a "copy" of a script
to read checkboxes, the second one gives me at least the index of the
selection (but not the value). With the alert command I am only displaying
the result:
(Form = myform
fieldname = country)
1)
for(j=0;j<document.myform.country.length;j++) {
if(myform.country[j].checked) {
var myvar=myform.country[j].value
}
}
alert(myvar); /*result ist an empty string*/
2)
k = document.myform.country.selectedIndex;
var myvar2=myform.country[k].value;
alert(k); /*result is the index of the selected item*/
alert(myvar2); /*result is an empty string*/
my dropdown looks like this:
<select name="country" size="1">
<option selected></option>
<option>BELGIUM</option>
<option>BULGARIA</option>
</select>
What is the value of the item selected?
regards
arno
I have a form with a dropdown list. Now, I would like to know in javascript
what value was selected but I cannot figure that out.
Here are my two scripts that do not work, the first is a "copy" of a script
to read checkboxes, the second one gives me at least the index of the
selection (but not the value). With the alert command I am only displaying
the result:
(Form = myform
fieldname = country)
1)
for(j=0;j<document.myform.country.length;j++) {
if(myform.country[j].checked) {
var myvar=myform.country[j].value
}
}
alert(myvar); /*result ist an empty string*/
2)
k = document.myform.country.selectedIndex;
var myvar2=myform.country[k].value;
alert(k); /*result is the index of the selected item*/
alert(myvar2); /*result is an empty string*/
my dropdown looks like this:
<select name="country" size="1">
<option selected></option>
<option>BELGIUM</option>
<option>BULGARIA</option>
</select>
What is the value of the item selected?
regards
arno