I’m kinda new to jQuery, so this may be a silly question…
My problem is that i have a click event that triggers when I click any button with the class ajax-submit. What I’m trying to do is a simple multi-page form using ajax. It works great on the first step, but the second time I click on a button with the ajax-submit class, it won’t work.
Here is the code I’m using for the AJAX form submitting:
$(document).ready(function() {
$(".ajax-submit").click(function() {
var form_data = $('#unlockForm').serialize();
$('.ajaxgif').removeClass('hide');
$.ajax({
type: "POST",
url: "formprocess.php",
data: form_data,
success: function(respuesta) {
$('.ajaxgif').hide();
$('#process-container').html(respuesta);
},
error: function() {
$('.ajaxgif').hide();
alert("Error! Please try again");
}
});
return false;
});
});
And the form codes are simple like this
<form name="unlockForm" id="unlockForm" method="post">
<input type="text" onFocus="if(this.value=='Introduce IMEI') this.value=''" value="Introduce IMEI" onBlur="if(this.value=='') this.value='Introduce IMEI';" name="imei" class="textbox part1" id="imei">
<input type="button" class="ajax-submit inputbutton part1" value="Next" name="simple" id="next-imei">
</form>
In both forms the buttons have the ajax-submit class, I checked and I don’t have any typo mistake, you may ask why I don’t use submit buttons, well, I tried but I didn’t figured out how to manage the submit event correctly, it kept recharging the page.
The
clickevent is not attached to the new.ajax-submitelements.You will need to use delegate event like with
onordelegateto do so.Table of delegate event functions:
onUseful docs: