Change input background color if the value of the input is valid in database
<p>The logic i am trying to do is:</p>

<pre><code>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;
</code></pre>

<p>I have my code like this:</p>

<p>index.php</p>

<pre><code>&lt;?php
include 'my database connection page';
include 'page that return me an array with all the emails';
?&gt;
&lt;form method="POST"&gt;
    &lt;input type="text" name="email" id="email_field" onFocus="changeColorEmail(this)"&gt;
    &lt;input type="submit"&gt;
&lt;/form&gt;
</code></pre>

<p>scripts.js</p>

<pre><code>function changeColorEmail(which) {
    which.value = which.value.split(' ').join('')
        if (which.value == "&lt;? echo $user_data['user_email'] ?&gt;") {
            which.style.background = '#ffffff';
    }else {
            which.style.background = "#ffebe8";
    }
}
</code></pre>

<p>Any ideas are appreciated!</p>

<p><strong>user.php</strong> (contain a function that verify if the email exists in database)</p>

<pre><code>function email_exists($email){
    return (mysql_result(mysql_query("SELECT COUNT(user_id) FROM user WHERE user_email = '$email'"), 0) == 1) ? true : false;
}
</code></pre>
