| eberdome |
05-21-2012 02:56 AM |
Contact Form submit issue in IE8 and below
Hey All,
I seem to be having a problem with a contact form's jQuery, but the issue only happens in IE8 and below. As you will see below, the first image shows what the form looks like if there are errors and in all browsers other than IE8 and below experience this same error no matter how many times they click submit. However, in IE8 and below when the user clicks the submit button the first time the first image appears, but when they click it again, those "default" values (Please enter your name, etc) are being submitted and the form defaults to the PHP errors, as shown in the second image. I have posted my code below. Anyone know how to fix this so that it's the same in IE8 and below? Much appreciation in advance!
First Image
http://www.tylerwolfson.com/images/v/1.png
Second Image
http://www.tylerwolfson.com/images/v/2.png
jQuery code that handles the errors and submitting of the form
Code:
$(document).ready(function(){
$("div.successContact").hide();
$("#submitContact").click(function(){
$(".error").hide();
var hasError = false;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var nameVal = $("#name").val();
if(nameVal == '') {
$("#name").val('Please enter your name').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#name").val('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
var emailVal = $("#emailC").val();
if(emailVal == '') {
$("#emailC").val('Please enter your email').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#emailC").val('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
else if(emailVal == 'Please enter your email') {
$("#emailC").html('Please enter your email').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#emailC").html('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
else if(!emailReg.test(emailVal)) {
$("#emailC").val('Please enter a valid email').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#emailC").val('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
var subjectVal = $("#subject").val();
var bizNameVal = $("#biz_name").val();
var urlVal = $("#url").val();
var hearVal = $("#hear").val();
var messageVal = $("#message").val();
if(messageVal == '') {
$("#message").html('Please enter your message').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#message").html('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
else if(messageVal == 'Please enter your message') {
$("#message").html('Please enter your message').attr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;").focus(function() { $("#message").html('').removeAttr("style","border:1px solid #BB6666;background:#FFEFEF;font-style:italic;color:#999;"); });
hasError = true;
}
if(hasError == false) {
$("#contact-container input.send").after('<img src="http://www.hostoptix.com/images/spinner.gif" alt="" style="position:relative; top:3px; left:15px;" />');
$.post("http://www.hostoptix.com/sendEmail.php",
{ name: nameVal, emailC: emailVal, subject: subjectVal, biz_name: bizNameVal, url: urlVal, hear: hearVal, message: messageVal },
function(data){
$("#contact-container").delay('1000').fadeOut('1500');
$("div.successContact").delay('1500').fadeIn('1500').append('<span style="margin-left:150px; color:#FEA92A; font-size:20px;">Thank you, <b style="text-transform:capitalize;">'+nameVal+'</b>!<span style="margin-top:3px; color:#333; font-size:16px;">Your message has been sent.</span><br/><span style="font-size:13px; color:#777;">Please keep an eye on your inbox, we\'ll be sending you an email shortly!<br/><br/>Need to send another message? <a href="/contact.php">Click Here</a></span>');
}
);
}
return false;
});
});
Thanks in advance!
|