Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts

    SelectedIndex Help With Dropdown

    Hey Guys,

    I've got a small issue and it has to be something simple I'm missing. I've got the following list of 10 links that work just fine:

    Code:
    <a href="javascript:showGroup('05', '.05')">link name</a>
    <a href="javascript:showGroup('10', '.10')">link name</a>
    
    ...
    The values inside the showGroup function are all that change and I'm trying to move them into a dropdown. However I can't get it work correctly. This is what I currently have:


    Code:
    <select name="showGroup_dropdown" onChange="document.getElementById('selectedIndex.value')">
      <option value="javascript:showGroup('05', '.05')">Option 1<option>
      <option value="javascript:showGroup('10', '.10')">Option 2<option>
      ...
    </select>
    I want the select statement to pull the value from the option value selected, and then run the function that goes with it. However my code inside the OnChange event is incorrect. I can hardcode a single value and have it work:

    Code:
    onChange="showGroup('05', '.05')"
    But obviously I need to pull the correct value from the option selected in the dropdown.

    Does anyone have any advice? Any suggestions would be appreciated.

    Thanks.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Lightbulb Try this and report back ...

    Assuming no errors elsewhere, try this:
    Code:
    <select name="showGroup_dropdown" onChange="this.value">
      <option value="javascript:showGroup('05', '.05')">Option 1<option>
      <option value="javascript:showGroup('10', '.10')">Option 2<option>
      ...
    </select>
    Code not tested ...

  • Users who have thanked jmrker for this post:

    kraftomatic (01-23-2009)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Code:
    <select name = "showGroup_dropdown" id="showGroup_dropdown" onchange="getValue()">
    <option value="javascript:showGroup('05', '.05')">Option 1< /option>
    <option value="javascript:showGroup('10', '.10')">Option 2< /option>
    </select>
    
    <script type = "text/javascript">
    function getValue() {
    var group = document.getElementById("showGroup_dropdown").value;
    alert (group);
    }
    </script>
    Code tested ......



    I have nothing but confidence in you. And very little of that.
    Groucho Marx (1890 - 1977)

  • Users who have thanked Philip M for this post:

    kraftomatic (01-23-2009)

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    That helps a bunch, thanks guys.


  •  

    Posting Permissions

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