Ok, so I use ModalBox to create an email form on my website..however, i need the modal box to send the email not to me, but to the user who added the car(its a car selling website), and so I need to pass the $email variable to the sendmessage.php.
This is what i did so far:
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
setTimeout("$.fancybox.close()", 10);
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>Se trimite...</em>");
$.ajax({
type: 'POST',
url: 'http://automoka.ro/sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Mesajul a fost trimis!</strong></p>");
setTimeout("$.fancybox.close()", 10);
$_POST['contact'] = $email;
});
}
}
});
}
});
});
and in the php sender :
$email = $_POST['contact'];
$sendto = $email;
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
if(#mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
What am I doing wrong? Please help....Thanks in advance!
EDIT:
Nevermind..figured it out!...I added another textarea which was hidden to the modalbox...and used post to get it to sendmessage.php.
Related
I have a HTML form that when posted fires an JQuery script to check a validation function before sending data to an ajax call to insert the data into a mySQL database.
It works as it should, except when it is running an ajax check to see if the posted email address already exists in the database.
I need the email_error var to return true if the response from the ajax call is not 'success'. My code:
function validate_add_relative() {
var check_error = false;
var email_error = false;
var title = document.forms["add_relative_form"]["title"].value;
if (title == null || title == "") {
check_error = true;
}
var first_name = document.forms["add_relative_form"]["first_name"].value;
if (first_name == null || first_name == "") {
check_error = true;
}
var surname = document.forms["add_relative_form"]["surname"].value;
if (surname == null || surname == "") {
check_error = true;
}
var phone = document.forms["add_relative_form"]["phone"].value;
if (phone == null || phone == "") {
check_error = true;
}
var email = document.forms["add_relative_form"]["email"].value;
if (email == null || email == "") {
check_error = true;
}
var address = document.forms["add_relative_form"]["address"].value;
if (address == null || address == "") {
check_error = true;
}
var postData = $(this).serializeArray();
$.ajax(
{
url : '<?php echo WEB_URL . 'controllers/ajax/check_relative_email.php'; ?>',
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR) {
if(data == 'success') {
email_error = false;
return true;
}
else {
alert('test');
email_error = true;
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Email is already in use. Please choose another.');
}
},
error: function(jqXHR, textStatus, errorThrown)
{
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Error. Please try again later.');
email_error = true;
}
});
if (email_error == true) {
alert("Please choose another email address, that one is already in use.");
return false;
}
if (check_error == true) {
alert("Please ensure you fill in all mandatory fields.");
return false;
}
if (email_error == false && check_error == false) {
return true;
}
}
$('.add_relative_form').submit(function(e) {
e.preventDefault();
if(validate_add_relative()) {
var ajaxurl = '<?php echo WEB_URL; ?>controllers/ajax/add_relative.php',
form_data = $('.add_relative_form').serialize();
$.post(ajaxurl, form_data, function (response) {
//location.reload();
});
}
});
When running the above code, the first part (Form validation) works as it should, and it also gives the alert and does the class hiding after. But it carries on and is not catching the fact that email_error is set to true after the alert line. So it continues through the code and adds the entry through the last ajax post controllers/ajax/add_relative.php
add complete function after error and write your code inside that function
complete:function(data, textStatus, jqXHR) {
if(data == 'success') {
email_error = false;
return true;
}
else {
alert('test');
email_error = true;
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Email is already in use. Please choose another.');
}
},
JavaScript is asynchronous in the sense that it can make, for example, Ajax calls. Hence your outer conditions will get mislead. Try to add return statement inside AJAX response for expected result.
Please try following solution
function validate_add_relative() {
var check_error = false;
var email_error = false;
var title = document.forms["add_relative_form"]["title"].value;
if (title == null || title == "") {
check_error = true;
}
var first_name = document.forms["add_relative_form"]["first_name"].value;
if (first_name == null || first_name == "") {
check_error = true;
}
var surname = document.forms["add_relative_form"]["surname"].value;
if (surname == null || surname == "") {
check_error = true;
}
var phone = document.forms["add_relative_form"]["phone"].value;
if (phone == null || phone == "") {
check_error = true;
}
var email = document.forms["add_relative_form"]["email"].value;
if (email == null || email == "") {
check_error = true;
}
var address = document.forms["add_relative_form"]["address"].value;
if (address == null || address == "") {
check_error = true;
}
if(check_error===false){
var postData = $(this).serializeArray();
$.ajax(
{
url : '<?php echo WEB_URL . 'controllers/ajax/check_relative_email.php'; ?>',
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR) {
if(data == 'success') {
return true;
}
else {
alert('test');
return false;
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Email is already in use. Please choose another.');
}
},
error: function(jqXHR, textStatus, errorThrown)
{
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Error. Please try again later.');
return false;
}
});
}
else{
return false;
}
}
$('.add_relative_form').submit(function(e) {
e.preventDefault();
if(validate_add_relative()) {
var ajaxurl = '<?php echo WEB_URL; ?>controllers/ajax/add_relative.php',
form_data = $('.add_relative_form').serialize();
$.post(ajaxurl, form_data, function (response) {
//location.reload();
});
}
});
UPDATES
change following code :
if(data == 'success') {
return true;
}
else {
alert('test');
return false;
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Email is already in use. Please choose another.');
}
To
if(data == 'success') {
return true;
}
else {
alert('test');
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Email is already in use. Please choose another.');
return false;
}
You can check, if the email already exists by using .blur() as soon after the user enters their email, you send AJAX call to check if the email exists and disable the submit button and show proper message to the user.
Form
<form action="" name="add_relative_form" class="add_relative_form">
<input type="text" name="title">
<input type="text" name="first_name">
<input type="text" name="surname">
<input type="text" name="phone">
<input type="text" id="email" name="email"> <!-- give email an id -->
<input type="text" name="address">
<input type="submit" id="sub" value="Sub"> <!-- give submit an id -->
Javascript
function validate_add_relative() {
var check_error = false;
var email_error = false;
var title = document.forms["add_relative_form"]["title"].value;
if (title == null || title == "") {
check_error = true;
}
var first_name = document.forms["add_relative_form"]["first_name"].value;
if (first_name == null || first_name == "") {
check_error = true;
}
var surname = document.forms["add_relative_form"]["surname"].value;
if (surname == null || surname == "") {
check_error = true;
}
var phone = document.forms["add_relative_form"]["phone"].value;
if (phone == null || phone == "") {
check_error = true;
}
var email = document.forms["add_relative_form"]["email"].value;
if (email == null || email == "") {
check_error = true;
}
var address = document.forms["add_relative_form"]["address"].value;
if (address == null || address == "") {
check_error = true;
}
if (email_error == true) {
alert("Please choose another email address, that one is already in use.");
return false;
}
if (check_error == true) {
alert("Please ensure you fill in all mandatory fields.");
return false;
}
if (email_error == false && check_error == false) {
return true;
}
}
$('.add_relative_form').submit(function (e) {
e.preventDefault();
if (validate_add_relative()) {
var ajaxurl = '<?php echo WEB_URL; ?>controllers/ajax/add_relative.php',
form_data = $('.add_relative_form').serialize();
$.post(ajaxurl, form_data, function (response) {
//location.reload();
console.log(response)
});
}
});
$('#email').on('blur', function () {
$.ajax({
url: '<?php echo WEB_URL . 'controllers/ajax/check_relative_email.php'; ?>',
type: "POST",
data: {email: $(this).val()},
success: function (data, textStatus, jqXHR) {
if (data == 'success') {
$('#sub').prop('disabled', false);
}
else {
$('.relative_email_error').show();
$('.relative_email_error').html('Email is already in use. Please choose another.');
$('#sub').prop('disabled', true);
}
},
error: function (jqXHR, textStatus, errorThrown) {
$('.relative_email_error').removeClass('hidden');
$('.relative_email_error').html('Error. Please try again later.');
}
});
})
Then in your PHP get the email from post
<?php
$email = $_POST['email'];
// your SQL code here
I am trying to send an email with PHP and AJAX, and it finally works, but it won't display validation errors returned from the server. I guess I'm doing something wrong in iterating through that data, or just don't understand something with connecting PHP and jQuery with JSON.
PHP mail script on server:
$to = "mymail#gmail.com";
if (isset($_POST['name'], $_POST['mail'], $_POST['text'])) {
if (empty($_POST['name'])) {
$errors[] = "Molimo unesite Vaše ime";
} else {
$contact_name = htmlentities($_POST['name']);
}
if (empty($_POST['mail'])) {
$errors[] = "Molimo unesite Vašu email adresu.";
} else if (strlen($_POST['mail']) > 60) {
$errors[] = "Vaša email adresa je predugačka.";
} else if (filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) === false ) {
$errors[] = "Unesite validnu email adresu.";
} else {
$contact_mail = "<" . htmlentities($_POST['mail']) . ">";
}
if (empty($_POST['text'])) {
$errors[] = "Molimo unesite poruku.";
} else {
$contact_text = htmlentities($_POST['text']);
}
}
if (empty($errors) === true) {
if(isset($contact_text, $contact_name, $contact_mail)) {
$subject = "Mail from " . $contact_name ." via www.mysite.com";
$headers = "From: " . $contact_mail;
$sent = mail($to, $subject, $contact_text, $headers);
if ($sent) {
die("true");
} else {
return json_encode($errors);
}
}
}
Relevant jQuery:
var mailBroker = {
send : function() { //initial validation and sending to server
var contact_name = $('input[name="contact-name"]').val();
var contact_mail = $('input[name="contact-mail"]').val();
var contact_text = $('textarea[name="contact-text"]').val();
var status = ""; //send success status
if (contact_name === "" || contact_mail === "" || contact_text === "") {
//form not complete
} else {
$.post("includes/mail.php", { //post form data to server
name : contact_name,
mail : contact_mail,
text : contact_text
}, function(data) {
var response = data;
if (data === "true") { //succesful
mailBroker.setStatus('Poruka poslata.');
} else {
var parsedData = $.parseJSON(data);
$.each(parsedData, function() {
var that = $(this);
setStatus(that);
});
}
});
}
},
setStatus : function(status) {
$('textarea[name="contact-text"]').after('<span>' + status + '</span>');
}
}
And inside $(document).ready():
$('#contact-us form').submit(function(event) {
event.preventDefault();
mailBroker.send();
$(this).trigger('reset');
});
Can somebody point out what I am doing wrong?
Of course, I know that I could just do it on the client-side, but that it is bad practice. So I left that part out for now and assumed that invalid or no data got through for required form fields.
Answer form is easier to explain this. The logic in your code never gives your script a chance to output the errors to the AJAX. You'd need to change the logic so it will. Ie.
if (empty($errors) === true) {
if(isset($contact_text, $contact_name, $contact_mail)) {
$subject = "Mail from " . $contact_name ." via www.mysite.com";
$headers = "From: " . $contact_mail;
$sent = mail($to, $subject, $contact_text, $headers);
if ($sent) {
die("true");
} else {
die("false"); // with json_encode here, $errors will always be empty
}
}
} else {
die(json_encode($errors)); //$errors wasn't empty, this is where you need to hand it back to the JS.
}
This is why firebug or another tool would help. You'd see that the information you were wanting given to your JS wasn't there - that way you know to look at the PHP (server-side) since it isn't outputting as expected. If it was, you'd check in to the JS code to see why that isn't processing it as expected.
EDIT: Your javascript doesn't allow the PHP to execute when a field is empty, but you are wanting the feedback PHP will give if one is empty, so you'd want to change your JS to something like:
var mailBroker = {
send : function() { //initial validation and sending to server
var contact_name = $('input[name="contact-name"]').val();
var contact_mail = $('input[name="contact-mail"]').val();
var contact_text = $('textarea[name="contact-text"]').val();
var status = ""; //send success status
$.post("includes/mail.php", { //post form data to server
name : contact_name,
mail : contact_mail,
text : contact_text
}, function(data) {
var response = data;
if (data === "true") { //succesful
mailBroker.setStatus('Poruka poslata.');
} else {
var parsedData = $.parseJSON(data);
$.each(parsedData, function() {
var that = $(this);
setStatus(that);
});
}
});
},
setStatus : function(status) {
$('textarea[name="contact-text"]').after('<span>' + status + '</span>');
}
}
A little modification of Jon's answer because you will still need to extract the messages from the returned JSON:
var mailBroker = {
'send' : function() { //initial validation and sending to server
var contact_name = $('input[name="contact-name"]').val();
var contact_mail = $('input[name="contact-mail"]').val();
var contact_text = $('textarea[name="contact-text"]').val();
var status = ""; //send success status
$.post("includes/mail.php", { //post form data to server
name : contact_name,
mail : contact_mail,
text : contact_text
}, function(data) {
var response = data;
if (data === "true") { //succesful
mailBroker.setStatus('Poruka poslata.');
$('#contact-us form').trigger('reset');
} else { //validation failed
var parsedData = $.parseJSON(data);
var msg = '';
$.each(parsedData, function() {
var that = $(this);
for (var i = 0; i < that.size(); i++) {
msg += that[i];
}
mailBroker.setStatus(msg); //msg used to be 'that'
msg = '';
});
}
});
},
'setStatus' : function(status) {
$('#validation-msgs').prepend('<p class="validation-msg">' + status + '</p>');
}
}
Essentially - you will need to pass through parsed data to get each of the messages. The problem is that they are also stored as arrays - of characters. So you will need to pass through those, too, and append those characters to a message String.
Then, you should prepend those messages to some container for warnings so they are in the right order. If you don't do that, you will get [Object] instead of the message text.
Hope this helps.
Hi I think you messed up on your line 3 mail script.
if (isset($_POST['name'], $_POST['mail'], $_POST['text'])) {
because you will use comparison operators for that.
Like this below.
if (isset($_POST['name'] && $_POST['mail'] && $_POST['text'])) {
I just want to ask how can i allow #abc.co.uk or #def.com.tr or something else email extenssions. when user register my website ?
Like if user try to register with (name#hotmail.com) then this email is not allowing. But if user try to register with (name#abc.co.uk or #def.com.tr) then user can register the website.
$("#email").change(function()
{
var email = $("#email").val();
var msgbox = $("#estatus");
if(email.length >= 3)
{
$("#estatus").html('<div class="checking">Checking availability...</div>');
$.ajax({
type: "POST",
url: "check_mail.php",
data: "email="+ email,
success: function(msg){
$("#estatus").ajaxComplete(function(event, request, settings){
var d = msg;
var str=msg.substr(0, 2);
$("#estatus").html('');
if(str == 'OK')
{
$("#email").removeClass("no");
$("#email").addClass("yes");
//msgbox.html('<font color="Green"> Ok </font> ');
}
else
{
$("#email").removeClass("yes");
$("#email").addClass("no");
msgbox.html(msg);
}
});
}
});
}
else
{
$("#email").addClass("no");
$("#estatus").html('<div class="error">Enter a valid e-mail</div>');
}
return false;
});
PHP check_mail.php
<?php
error_reporting(0);
include_once 'includes/db.php';
include_once 'includes/Sc_Script.php';
$Sc = new Check_Email();
if(isSet($_POST['email'])){
$value=$_POST['email'];
// Check the mail is already in using or not
$check=$Sc->Login_Check($value,0);
if($check) {
echo '<div class="error">'.$value.' = This email address is already in use.</div>';
} else {
// Else continue
echo 'OK';
}
}
?>
First you need to pull out the domain and then you need to check that it is contained within some whitelist array:
function isDomainAllowed($email_address)
{
$domain = substr($email_address, strrpos($email_address, '#') + 1);
if (in_array(strtolower($domain), array(
'abc.co.uk',
'def.com.tr',
)))
{
return TRUE;
}
return FALSE;
}
if (isDomainAllowed($email_address))
{
// Allowed
}
else
{
// Not allowed
}
You have check each & every whitelist domain with the supplied email.
$emailList = array();
$emailList = ["abc.in","def.uk"];
$flag = false;
foreach($emailList as $email)
{
if(stripos($_POST['email'],$email) != false)
$flag = true;
}
if($flag == false)
echo "Invalid email domain";
I want to write (register section) code that can check if email have been used in past or the login is empty.
The code is working fine, but my ajax code dont run at all.
I checked everything, path to php file is good, variables are good etc. Don't how to solve it.
Code:
$('.login').submit(function(e) {
e.preventDefault();
var error = 0;
var self = $(this);
var $name = self.find('[type=name]');
var $email = self.find('[type=email]');
var $pass = self.find('[type=password]');
var emailRegex = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (!emailRegex.test($email.val())) {
createErrTult("Błąd! Email ma zły format!", $email)
error++;
}
//MY AJAX CODE
var email = $email.val();
$.ajax({
url: '../inc/rejestracja.php?action=emailcheck',
data: {
'email': email
},
type: 'POST',
success: function(odp) {
if (odp == 1) {
createErrTult("Błąd! taki email już istnieje w bazie!", $email)
error++;
}
}
});
if ($name.val().length > 1 && $name.val() != $name.attr('placeholder')) {
$name.removeClass('invalid_field');
} else {
createErrTult('Error! Wrong name!', $name)
error++;
}
if ($pass.val().length > 1 && $pass.val() != $pass.attr('placeholder')) {
$pass.removeClass('invalid_field');
} else {
createErrTult('Error! Wrong password!', $pass)
error++;
}
if (error != 0) return;
self.find('[type=submit]').attr('disabled', 'disabled');
self.children().fadeOut(300, function() {
$(this).remove()
})
$('<p class="login__title">sign in <br><span class="login-edition">welcome to A.Movie</span></p><p class="success">You have successfully<br> signed in!</p>').appendTo(self)
.hide().delay(300).fadeIn();
// var formInput = self.serialize();
// $.post(self.attr('action'),formInput, function(data){}); // end post
});
php:
<?php
include ("config.php");
if($action == "emailcheck"){
//sprawdzamy czy był już dodany plus
$test = mysql_num_rows(mysql_query("select * from uzytkownicy where email='$email'"));
if ($test > 0) {
$dodano = 1;
echo json_encode($dodano);
}
?>
First, you should try adding error callback:
$.ajax({
url: '../inc/rejestracja.php?action=emailcheck',
data: {
'email': email
},
type: 'POST',
success: function(odp) {
if (odp == 1) {
createErrTult("Błąd! taki email już istnieje w bazie!", $email)
error++;
}
},
error: function(xhr, textStatus, error) // THOSE ROWS
{
alert(error);
}
});
This may alert you about some occured error.
Second, you can try to use json instead of plain text:
Client-side:
$.ajax({
url: '../inc/rejestracja.php?action=emailcheck',
data: {
'email': email
},
dataType: 'json', // THIS ROW
type: 'POST',
success: function(odp) {
if (odp['result'] == 1) {
createErrTult("Błąd! taki email już istnieje w bazie!", $email)
error++;
}
},
error: function(xhr, textStatus, error)
{
alert(error);
}
});
Server-side:
<?php
include ("config.php");
if (isset($_GET['action'])){
$action = $_GET['action'];
if($action == "emailcheck") {
if(isset($_GET['email'])) {
$email = $_GET['email'];
//sprawdzamy czy był już dodany plus
$test = mysql_num_rows(mysql_query("select * from uzytkownicy where email='$email'"));
if ($test > 0) {
$dodano = 1;
echo (json_encode(array("result" => $dodano))); // THIS ROW
}
}
}
}
?>
before everything check you config.php file path .. In your case config.php should be in the same path with rejestracja.php and try this.. lets start with ajax
$.ajax({
url: '../inc/rejestracja.php?action=emailcheck',
data: {
email: email
},
type: 'GET',
success: function(odp) {
if (odp == 1) {
alert('Email exists');
}else{
alert('Email dosen\'t exists');
}
}
});
then in php
<?php
include ("config.php");
if (isset($_GET['action'])){
$action = $_GET['action'];
if($action == "emailcheck"){
if(isset($_GET['email'])){
$email = $_GET['email'];
//sprawdzamy czy był już dodany plus
$test = mysql_num_rows(mysql_query("select * from uzytkownicy where email='$email'"));
if ($test > 0) {
$dodano = 1;
echo ($dodano);
}
}
}
?>
you should get alert with ('Email exists')
I wrote some ajax validation for email check by verifying the availability using php the ajax script just displays whether email is available or not?
<script type="text/javascript">
$(document).ready(function()
{
$("#email_id").change(function(){
var email = $("#email_id").val();
var regdata = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(!(regdata).test($("#email_id").val()))
{
$("#email_id").css('border','1px solid red');
$("#email_id").focus();
$("#status").html("enter the valid emailid!");
return false;
}
else{
$("#email").css('border','1px solid #7F9DB9');
$("#email_id").html('Checking Email Availability...');
$.ajax({
type: "POST",
url: "fresherreg_email_avail.php",
data:"q="+ email,
success: function(server_response){
$("#status").ajaxComplete(function(event,request){
if(server_response == '0')
{
$("#status").html('Email Available');
}
else if(server_response == '1')
{
$("#status").html('Email Not Available');
}
});
}
});
}
});
});
</script>
and my php availability check code is
<?php
include_once("include_dao.php");
$q = $_REQUEST['q'];
if($q != "")
{
$row=DAOFactory::getTblFreshersRegistrationDAO()->queryByEmailId($q);
$num = count($row);
if($num > 0)
{
echo "1";
}
else
{
echo "0";
}
}
else
{
echo "Email Id should not be empty";
}
?>
what i need is?
it should show an alert using script until he choose a new mail id
It can be done this way . I will edit your code and add the required thing .
In the javascript/jquery part:
<script type="text/javascript">
$(document).ready(function()
{
$("#email_id").change(function(){
var email = $("#email_id").val();
var regdata = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(!(regdata).test($("#email_id").val()))
{
$("#email_id").css('border','1px solid red');
$("#email_id").focus();
$("#status").html("enter the valid emailid!");
return false;
}
else{
$("#email").css('border','1px solid #7F9DB9');
$("#email_id").html('Checking Email Availability...');
$.ajax({
type: "POST",
url: "fresherreg_email_avail.php",
data:"q="+ email,
success: function(server_response){
if(server_response == '0')
{
$("#status").append("<font color='green'>email available</font>");
}
else if(server_response == '1')
{
$("#status").append("<font color='red'>email already exits</font>");
}
else
{
$("#status").append("<font color='red'>"+server_response+"</font>");
}
}
});
}
});
});
</script>
Now in your php script .
<?php
include_once("include_dao.php");
$q = $_REQUEST['q'];
if($q != "")
{
$row=DAOFactory::getTblFreshersRegistrationDAO()->queryByEmailId($q);
$num = count($row);
if($num > 0)
{
echo "1";
}
else
{
echo "0";
}
}
else
{
echo "Email Id should not be empty";
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('#submit');
var emaildone = false;
var myRegForm = $("#registration"),email = $("#email_id"), status = $("#status");
myRegForm.submit(function(){
if(!emaildone)
{
alert("Email Id Already Exists!!! So Please Try Another Email Id");
email.attr("value","");
email.focus();
return false;
}
});
email.blur(function(){
$.ajax({
type: "POST",
data: "q="+$(this).attr("value"),
url: "fresherreg_email_avail.php",
beforeSend: function(){
status.html('<img src="images/loader.gif" align="absmiddle"><font color="blue">Checking Email Availability...</font>');
},
success: function(data){
if(data == "invalid")
{
emaildone = false;
status.html("<font color='red'>Inavlid Email!! Please Select a Vaild Email</font>");
}
else if(data != "0")
{
emaildone = false;
status.html('<img src="images/not_available.png" align="absmiddle"><font color="red">Email Already Exist</font>');
}
else
{
emaildone = true;
status.html('<img src="images/available.png" align="absmiddle"> <font color="green">Email Available</font>');
}
}
});
});
});
</script>
Change script to this.