Web Analytics Made Easy -
StatCounter using a dropdown selection as a submit button - CodingForum

Announcement

Collapse
No announcement yet.

using a dropdown selection as a submit button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    <select onchange="document.forms.formname.submit()">

    should do it
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

    Comment


    • #3
      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; Jul 3, 2002, 05:13 PM.

      Comment

      Working...
      X