I have a form with two different submit buttons. It looks like this:
Button "Ja" pressed - first submit button appears
Code of "Ja" button:
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submityes" id="submityes" class="btn btn-danger">Ticket abschicken</button>
</div>
Button "Nein" pressed - second submit button appears
Code of "Nein" button:
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submitno" id="submitno" class="btn btn-danger">Ticket abschicken</button>
</div>
When the first submit button is pressed the user should be redirected to submit1.php, when the second submit button is pressed the user should be redirected to submit2.php.
Function that redirects users to submit1/2.php:
$('document').ready(function () {
"use strict";
$(function () {
var submityesClicked;
$('#submityes').click(function () {
submityesClicked = true;
});
$('#submitno').click(function () {
submityesClicked = false;
});
$('#webform').submit(function (e) {
e.preventDefault();//prevent the default action
$.ajax({
type: "POST",
/*url: "process.php", //process to mail
data: $('form.contact').serialize(),*/
success: function (msg) {
window.location.replace(submityesClicked ? "/submit_resolved_yes.php" : "/submit_resolved_no.php");
},
error: function () {
alert("error");
}
});
});
});
});
The problem I have is the following: Whenever I press the "Enter" on the keyboard the form is submitted with the first submit button. So if I write something in the "Telefonnummer" field (which only appears when the "Nein" button was pressed) and press "Enter" then the form is submitted with the first submit button, even if that one is not even visible.
How can I disable the "Enter" button for the whole form so that it is submitted correctly?