Hi the website i have built has multiple forms that i want to handle using AJAX, each request goes to a separate PHP page and returns a string.
HTML
<form name="addUserModule" id="addUserModule" action="" method="POST">
<input type="checkbox" name="moduleToADD[]" value="1">
<input type="submit" value="Save" id="addUserModuleSubmit">
<form action="" method ="post" id="addNewModule" name="addNewModule">
<input type="text" name="newModule">
<input type="submit" value="Add Module" id="addNewModuleSubmit">
Jquery
$('#addUserModule').submit(function(e){
e.preventDefault(); //Prevent the normal submission action
var form = this;
$.ajax({
url:'addUserModules.php',
data:$(form).serialize(),
type:'POST',
success: function(msg) {
displayNotification(msg);
}
});
});
$('#addNewModule').submit(function(e){
e.preventDefault(); //Prevent the normal submission action
var form = this;
$.ajax({
url:'addNewModule.php',
data:$(form).serialize(),
type:'POST',
success: function(msg) {
displayNotification(msg);
}
});
});
The first form works fine, but the second form runs the same function that i made for the first form. Im using the HTML id's to determine the difference.