Below there is a jQuery I use to add some entries in the DB. It is working correctly. I use the same one in the same file to remove some data. The form of the remove-from-db has id RemoveMe and it posts to $.post("add-to-db.php?id=<?php echo (int)$_GET['id'] ?>"
Below you can see the add-to-db script with form id AddMe.
My question is if there is a way to make these two in one. Thank you.
$(function(){
$("#AddMe").submit(function(e){
e.preventDefault();
$.post("add-to-db.php?id=<?php echo (int)$_GET['id'] ?>", $("#AddMe").serialize(), function (data){
$("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
$("#submit").attr('disabled',true);
$("#submit").unbind('click');
$("#message_post").html("Thank you");
setTimeout(function () { $("#message_post").hide(); window.location.href = "product.php?id=<?php echo (int)$_GET['id'] ?>"; }, 2000);
});
});
});
<form id="AddMe">
<input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png">
</form>
<div id="message_post"></div>
$(function(){
$("#RemoveMe").submit(function(e){
e.preventDefault();
$.post("remove-from-db.php?id=<?php echo (int)$_GET['id'] ?>", $("#RemoveMe").serialize(), function (data){
$("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
$("#submit").attr('disabled',true);
$("#submit").unbind('click');
$("#message_post").html("Thank you");
setTimeout(function () { $("#message_post").hide(); window.location.href = "product.php?id=<?php echo (int)$_GET['id'] ?>"; }, 2000);
});
});
});
<form id="RemoveMe">
<input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png">
</form>
<div id="message_post"></div>
You could use an array of object literals to store the id and url pairs