How to prevent form submission for a form using onchange to submit the form when certain values are

Posted by Terrence Brannon on Stack Overflow See other posts from Stack Overflow or by Terrence Brannon
Published on 2010-04-05T18:39:56Z Indexed on 2010/04/05 18:43 UTC
Read the original article Hit count: 373

Filed under:
|
|
|

I have a form I have built:

<form class="myform" action="cgi.pl">
  <select name="export" onchange='this.form.submit()'> 
    <option value="" selected="selected">Choose an export format</option> 
    <option value="html">HTML</option> 
    <option value="csv">CSV</option> 
  </select>
</form>

Now, this form works fine if I pull down and select "HTML" or "CSV". But if I hit the back button and select "Choose an export format", the form is submitted, even though I dont want it to be.

Is there any way to prevent form submission for that option?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about form