The logic i am trying to do is:
input field starts white (Normal);
after somebody finish typing, if the email does not exists, the input gets light red;
if the email exists in the database, the input becomes white again;
I have my code like this:
index.php
<?php
include 'my database connection page';
include 'page that return me an array with all the emails';
?>
<form method="POST">
<input type="text" name="email" id="email_field" onFocus="changeColorEmail(this)">
<input type="submit">
</form>
scripts.js
function changeColorEmail(which) {
which.value = which.value.split(' ').join('')
if (which.value == "<? echo $user_data['user_email'] ?>") {
which.style.background = '#ffffff';
}else {
which.style.background = "#ffebe8";
}
}
Any ideas are appreciated!
user.php (contain a function that verify if the email exists in database)
function email_exists($email){
return (mysql_result(mysql_query("SELECT COUNT(user_id) FROM user WHERE user_email = '$email'"), 0) == 1) ? true : false;
}