Reputation: 1
I got multiple forms that refresh a single div by using some jquery code as shown below. It refers to the class of the form, so that the code is the same for all forms. Problem is, it only takes the input from the last form and sends its to the div, not matter what form is clicked. They should instead send all different information, depending on which form button is clicked.
$(document).ready(function(){
$(".formlistmenu").validate({
submitHandler: function(form) {
// do other stuff for a valid form
$.post('listmenu.php', $(".formlistmenu").serialize(), function(data) {
$('#select').html(data);
});
}
});
});
<form name="myform1" class="formlistmenu" action="" method = "post">
<input type="hidden" name="selectstuff" value ="resources">
<input type="image" SRC="resources.gif" title="resources">
</form>
<form name="myform2" class="formlistmenu" action="" method = "post">
<input type="hidden" name="selectstuff" value ="items">
<input type="image" SRC="resources.gif" title="resources">
</form>
Upvotes: 0
Views: 1702
Reputation: 44740
Try this
$(".formlistmenu").each(function(){
$(this).validate({
submitHandler: function(form) {
// do other stuff for a valid form
$.post('listmenu.php', $(this).serialize(), function(data) {
$('#select').html(data);
});
}
});
});
Upvotes: 2