All,
I have the following jQuery code:
jQuery("#data_form").submit(function() {
event.preventDefault();
alert("it submits");
});
When I submit the form in Chrome it works fine but not in IE8. I tried to change the code to something like this:
jQuery("#data_form").submit(function(e) {
e.preventDefault();
alert("it submits");
});
This however still posts the page. Any idea on how to make this code work in IE8?
***EDIT: I tried to simplify the code for readability on here. However I tried the answer below and it didn’t work yet. Here is the complete code:
jQuery("#event_form").submit(function(e) {
e.preventDefault();
jQuery("#results").html('');
already_submitted = jQuery("#check_submission").val();
create_yes_no = jQuery("#create_yes_no").val();
if(already_submitted!="yes" && create_yes_no=="yes" ){
jQuery.post(site_url + "save_event_form.php", jQuery(this).serialize(),
function(data) {
//alert("Data Loaded: " + data);
var results = jQuery("#results");
results.html(data+"<br><br>");
results.show(); // re-display the div
setTimeout(function(){ // then fade it out....
results.fadeOut();
}, 5000); // ...after 5 seconds
jQuery("#check_submission").val("yes");
});
}else if(create_yes_no!="yes"){
jQuery.post(site_url + "save_event_form.php", jQuery(this).serialize(),
function(data) {
//alert("Data Loaded in the create yes or no yes: " + data);
var results = jQuery("#results");
results.html(data+"<br><br>");
results.show(); // re-display the div
setTimeout(function(){ // then fade it out....
results.fadeOut();
}, 5000); // ...after 5 seconds
});
}else{
alert("You already submitted this user once. Refresh the page to add another one.");
}
return false;
});
Thanks!
event.preventDefault doesn’t work in IE8. I changed it to be this code and it works good now: