Click event on submit buttons only fires once
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-04-27T14:31:30Z
Indexed on
2010/04/27
14:33 UTC
Read the original article
Hit count: 349
I subscribe to the click event on all submit buttons on my page once loaded. All buttons fire off the correct event when clicked, but this only works once. If you click any two buttons in a row the second button submits the form normally as opposed to running the script. What am I doing wrong?.
Note: I load the form data from "myurl" using .load()
then hook up to the submit buttons' click events in the complete event.
$(document).ready(function()
{
//Load user content
$("#passcontent").load("myurl", function()
{
//subscribe to click events for buttons to post the data back
$('input[type=submit]').click(function()
{
return submitClick($(this));
});
});
});
function submitClick(submitButton)
{
submitButton.attr("disabled", true);
alert(submitButton.closest("form").serialize());
$.post("myurl",
submitButton.closest("form").serialize(),
function(data)
{
alert("woop");
$("#passcontent").html(data);
});
//Prevent normal form submission process from continuing
return false;
}
© Stack Overflow or respective owner