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 7 of 7
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Dropdown menu submit on change??

    Hello,
    I trying to figure out how to submit a form when an option has been selected from a drop menu..

    my code:

    <form method=post name=FormVote onChange="javascript: document.forms['FormVote'].submit()">
    <select name="vote">
    <option selected>rate profile</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
    </form>

    i thought it should be something like that, but it's not working,
    I get the error: Object doesn't support this property or method..

    any ideas?

    thanks in advance for your time!
    -Ken

  • #2
    New Coder
    Join Date
    May 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe you could try putting the onchange handler on the <select>? Not sure but it might work.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    hmm, no that didn't work either,
    i'm not getting an error doing it that way, but it still doesn't submit the form.

    any other ideas?

    -Ken

  • #4
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Put the onchange handler in the select element not the form element
    Code:
    <select name="vote" onChange="document.forms['FormVote'].submit()">
    There is no change in the form but there is in the select therefore it won't fire in the form but will fire for the select. Notice you don't need "javascript:" either. I tested it by giving the form an action attribute. Hope that helps.
    OOOPs sorry Ken .Should read the post more carefully. Works for me.
    Last edited by glenmac; 07-23-2005 at 05:59 PM.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, i've tried this both ways, and still nothing is working,

    here my code again,

    first way i tried:
    PHP Code:
    <form method="get" name="FormVote">
    <
    select name="vote" onChange="document.forms['FormVote'].submit()">
    <
    option selected>rate profile</option>
    <
    option value="1">1</option>
    <
    option value="2">2</option>
    <
    option value="3">3</option>
    <
    option value="4">4</option>
    <
    option value="5">5</option>
    </
    select>
    </
    form

    second way:

    PHP Code:
    <form method="get" name="FormVote">
    <
    select name="vote">
    <
    option selected>rate profile</option>
    <
    option value="1" onChange="document.forms['FormVote'].submit()">1</option>
    <
    option value="2" onChange="document.forms['FormVote'].submit()">2</option>
    <
    option value="3" onChange="document.forms['FormVote'].submit()">3</option>
    <
    option value="4" onChange="document.forms['FormVote'].submit()">4</option>
    <
    option value="5" onChange="document.forms['FormVote'].submit()">5</option>
    </
    select>
    </
    form
    any other ideas??
    thanks again for your time!

  • #6
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this works for me. Noticed you changed it to "get" check the address bar after a selection.
    <form method="get" name="FormVote">
    <select name="vote" onChange="document.forms['FormVote'].submit()">
    <option selected>rate profile</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
    </form>

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by angst
    PHP Code:
    <form method="get" name="FormVote">
    <
    select name="vote" onChange="document.forms['FormVote'].submit()"
    That should work. Just make sure you don't have other elements with the name FormVote. The shorter version of that is:

    <select name="vote" onChange="this.form.submit()">

    If nothing is working, check if an error occurs in the Javascript console (Firefox) or there is an ! icon in the status bar (IE).
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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