Results 1 to 4 of 4

Thread: [stupid mistake resolved] Get the selected option from a form

  1. #1
    Tygur
    Guest

    [stupid mistake resolved] Get the selected option from a form

    Okay, I've tried everything. I even took some sample code from MSDN and copied that. I'm sure I'm doing something wrong, but I don't know what it is and I'm getting frustrated.

    All I need is some working JavaScript code that shows the currently selected item in a Select object (the combobox made by the SELECT tag). That's it. Just have the script show the item using alert() and I'll be happy.

    Then I'll compare whatever you post with what I have and try to figure this mess out.

  2. #2
    Tygur
    Guest
    I left it for a while and came back.

    After getting a fresh look at it, I realized what I did wrong. The problem I was getting was the script kept thinking the first option was selected. It turned out that I had the value of all the options set to the same thing. I had cut and pasted the tags, but forgot to change them...

  3. #3
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    hi

    Code:
    <script language="javascript">
    function ShowSelect(t)
    {
    alert("The Nth element selected  : " + t.selectedIndex);
    alert("The Value of the selected : " + t.value);
    alert("Other way (seee code ) :  " + document.myform.myselect.selectedIndex);
    alert("Other way (seee code ) :  " + document.myform.myselect.value);
    selectednum = t.selectedIndex;
    alert("One more way (seee code ) :  " + document.myform.myselect[selectednum].value);
    }
    </script>
    </HEAD>
    <BODY>
    
    <form name="myform">
    <select name="myselect" onchange="ShowSelect(this);">
    <option value="none">Select</option>
    <option value="first">First</option>
    <option value="second">Second</option>
    <option value="third">Third</option>
    <option value="fourth">Fourth</option>
    <option value="fifth">Fifth</option>
    
    </select>
    </form>
    Hope this helps.

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    late....

    appears u got faster then my isp could get me on to the net.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width