#1
  1. a lazy guy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Hong Kong
    Posts
    99
    Rep Power
    14

    Question Javascript: Form problem


    Hello,

    I got many Select Boxes in a HTML form, and they all get a different select box name. Eg.

    <SELECT Name="Hello_100" OnChange="MyTest(6, 'Hello_100', this.form)">
    <OPTION Value="1">Read</OPTION>
    <OPTION Value="2">Write</OPTION>
    <OPTION Value="3">Delete</OPTION>
    </SELECT>

    <SELECT Name="Hello_154" OnChange="MyTest(2, 'Hello_154', this.form)">
    <OPTION Value="1">Read</OPTION>
    <OPTION Value="2">Write</OPTION>
    <OPTION Value="3">Delete</OPTION>
    </SELECT>

    <SELECT Name="Hello_291"OnChange="MyTest(3, 'Hello_291', this.form)">
    <OPTION Value="1">Read</OPTION>
    <OPTION Value="2">Write</OPTION>
    <OPTION Value="3">Delete</OPTION>
    </SELECT>

    and I got a javascript function:
    function MyTest(ID, selectboxname, theform)
    {
    // how do I get the value of the selected option?
    alert(thisform.selectname.options[thisform.selectname.selectedIndex].value);
    }


    As you can see in my javascript function MyTest, the statement
    thisform.selectname.options[thisform.selectname.selectedIndex].value
    will not return the selected option value.
    How do I get the selected option value? The selected box name is generated randomly.
    pls help.
  2. #2
  3. No Profile Picture
    Beelzebub
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    The nether regions...ok, San Diego
    Posts
    164
    Rep Power
    14
    <SELECT Name="Hello_100" OnChange="MyTest(6, this.name, this.value)">
    <OPTION Value="1">Read</OPTION>
    <OPTION Value="2">Write</OPTION>
    <OPTION Value="3">Delete</OPTION>
    </SELECT>

    function MyTest(ID, selectboxname, thevalue)
    {
    alert(thevalue);
    }

IMN logo majestic logo threadwatch logo seochat tools logo