mukesh
mukesh

Reputation: 127

form submits even when I click cancel in confirm form submission dialog

This might be some stupidity from my part but I cant figure this out. Pls see the code below.

<%= submit_tag "Send Request", :class=>"btn btn-primary", onclick:"submit_form();"%>

<script type="text/javascript">
  function submit_form(){
  var email = document.getElementById('customer_email').value;
  return confirm("An email will be sent to "+email+" on behalf of your request. Proceed?");
    }   
</script>

The form submits even when I click cancel. What am I doing wrong here? Thanks in advance.

Upvotes: 0

Views: 89

Answers (2)

DeepInJava
DeepInJava

Reputation: 1961

Your cancel button should not be a type of "submit"

Upvotes: 0

Marko Krstic
Marko Krstic

Reputation: 1447

try instead of

onclick:"submit_form();"

this:

onclick: "return submit_form();"

Upvotes: 2

Related Questions