Forum Moderators: open

Message Too Old, No Replies

Problems with script

         

suf3r

12:01 am on Dec 19, 2009 (gmt 0)

10+ Year Member



Hello,
Problems with script:

html


<div id="box_form">
<div class="get_updates">
<input type="button" id="button_1" class="btn-get-updates" value="Get Updates !"/>
</div>
<div class="form_div">
<form id="contactForm" action="mail.php" method="post">
<div class="text-div">
<input type="text" name="email" id="email" class="text" value="Enter your e-mail here" onclick="this.value=''"/>
</div>
<div class="submit-div">
<input type="submit" name="submit" id="submit" class="submit" value="GO"/>
</div>
</form>
</div>
<div class="thank_you">
<input type="button" id="button_3" class="btn-get-updates" value="Thank you !"/>
</div>
</div>
</div>

.js

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")¦([\w-]+(?:\.[\w-]+)*)¦("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)¦(@\[?((25[0-5]\.¦2[0-4][0-9]\.¦1[0-9]{2}\.¦[0-9]{1,2}\.))((25[0-5]¦2[0-4][0-9]¦1[0-9]{2}¦[0-9]{1,2})\.){2}(25[0-5]¦2[0-4][0-9]¦1[0-9]{2}¦[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}
/*FORM validation and div changing*/
$(document).ready(function() {
$('.form_div').hide();
$('.thank_you').hide();
$("#button_1").click( function () {
$(this).parent().hide();
$('.form_div').fadeIn(1000);
});
$("#button_3").click( function () {
$(this).parent().hide();
$('.get_updates').fadeIn(1000);
});
/*email validatin*/
$("#submit").click(function() {
var email = $("input#email").val();
if(!isValidEmailAddress(email)){
$("input#email").focus();
$("input#email").val('Enter a valid e-mail');
return false;
}
})
/*form submit*/
$("form#contactForm").submit(function() {
var email = $("input#email").val();
$.ajax({
url:'mail.php',
type:'post',
data: "email="+email,
success: function(msg){
if (msg==0)
{
$("input#email").focus();
$("input#email").val('Some trouble on sending');
}
if (msg==1)
{
$('.form_div').hide();
$('.thank_you').fadeIn(1000);
}
}
});
return false;
});
/*end formsubmit*/
});

Then i type invalid email i got Enter a valid e-mail (thats ok), bet then enter a valid email i get Some trouble on sending.

Maybe problems with script or something ?

Fotiman

3:45 pm on Dec 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you using jQuery? If so, then I believe the success callback function expects 2 parameters. The first is the data returned from the server, the second is a string describing the status. In your example, I only see one parameter (msg). It would seem to indicate that the server is returning a value of 0, so perhaps you should perform some logging at the server level to see what it is doing with the request.

If you still need help with this, please post more info regarding what you see at the server side.