I have a Jquery function that I want to run when a form is Submitted. Here is the Jquery that is supposed to detects when form is submitted, stops the form from running it's default, and and run my code:
$( ".submit-button" ).submit(function( event ){
event.preventDefault();
var button = $(this).attr("id");
var url = 'https://myurl.com/AddAppointment.php';
$.ajax({
type: "POST",
url: url,
data: $('#SchedulePosition').serialize(),
success:function(){
if(button == 'SaveandReturn'){
window.location.href = "Photography and Editing Jobs.html";
}else if(button == 'SaveandView'){
window.location.href = "Photography and Editing Jobs.html";
}
}
});
});
And here are the submit buttons being used to submit the form:
<input class="btn btn-primary submit-button" style="width:50%; height:60px; float:left; font-size:18px; white-space:normal;"
id="SaveandReturn" type="submit" value="Save and Return to Photoshoot List">
<input class="btn btn-primary submit-button" style="width:50%; height:60px; float:right; font-size:18px; white-space:normal;"
id="SaveandView" type="submit" value="Save and View My Photoshoots">
And Finally, Here is my Form Header :
<form id="SchedulePosition" action="#" method="POST">
Whenever I click either of the buttons, the page just refreshes, which means that the code isn't running, but I can't figure out why it wouldn't. There are no errors that pop up in the console, nothing strange happening, it's just not triggering the Jquery.