[thelist] Obtaining value from Select box in Javascript

Warden, Matt mwarden at odyssey-design.com
Mon Aug 7 12:52:21 CDT 2000


You're gonna smack yourself...

> 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);

this should be:
document.form1.select2.options[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>

You have no value attributes in your option tags. So, it's working, but you
can't tell.

Oh, oh, please stop banging your head. You're gonna dent your desk up.

--
mattwarden
mattwarden.com





More information about the thelist mailing list