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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using a dropdown selection as a submit button

    I need a drop down box selection to act as a submit button, to post data to another webpage when it is selected- how will this work?
    Thanks
    -Ian

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <select onchange="document.forms.formname.submit()">

    should do it

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    I'm guessing you don't want the entire SELECT to submit - just one particular option; so...

    <form onsubmit="alert('OK');return false">
    <select onchange="if(this.selectedIndex==4)this.form.submit()">
    <option selected="selected">choose</option>
    <option>option 1</option>
    <option>option 2</option>
    <option>option 3</option>
    <option>submit form</option>
    </select>
    </form>

    Do it this way if you're not using a regular submit button anywhere. If you are, try this:

    <form onsubmit="alert('OK');return false">
    <select onchange="if(this.selectedIndex==4)sub.click()">
    <option>choose</option>
    <option>option 1</option>
    <option>option 2</option>
    <option>option 3</option>
    <option>submit form</option>
    </select>
    <input name="sub" type="submit">
    </form>

    Notice the alert() - calling Form.submit() directly doesn't activate the onsubmit event handler, while simulating a submit button click does - important if you're using the handler for validation routines. Your choice. Set the .selectedIndex==number to the submitting option number (Javascript counts from zero).
    Last edited by adios; 07-03-2002 at 11:13 PM.


  •  

    Posting Permissions

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