[thelist] Obtaining value from Select box in Javascript
Jagjeet Hayer
Jagjeet.Hayer at softwareag.co.uk
Mon Aug 7 12:21:34 CDT 2000
Hi all,
I hope someone can spot any obvious errors I may be making here. I would
have thought it straightforward to obtain the option value from a Select box
but I can't seem to get it at all.
This is my test code to try and get it working. I have tried several
permutations as you can see without success.
<HTML>
<HEAD>
<script language="JavaScript">
function getOptionValue(obj)
{
var index0, index1;
if (obj.name == "select1")
{
index0 = document.form1.select1.selectedIndex;
alert("index0 is : " + index0);
alert("test1 is : " +
document.form1.select2[document.form1.select1.selectedIndex].value);
alert("test2 is : " + document.form1.select2.options
[document.form1.select1.selectedIndex].value);
alert("test3 is : " + document.form1.select1.options[index0].value);
}
}
</script>
</HEAD>
<BODY>
<form name=form1>
<SELECT id=select1 name=select1 onChange="getOptionValue(this);">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</SELECT>
<SELECT id=select2 name=select2>
<option>00</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
</SELECT>
</form>
</BODY>
</HTML>
I can sleep peacefully tonight if anyone can help.
Thanks,
Jag.
More information about the thelist
mailing list