Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:32:45+00:00 2026-06-04T00:32:45+00:00

The logic i am trying to do is: input field starts white (Normal); after

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:32:46+00:00Added an answer on June 4, 2026 at 12:32 am

    ok, two ways to do this:

    Hard way:
    You’re going to need to capture the onblur event – which will fire when they leave the email box, you’re also going to need a bit of AJAX to send that value back to your script to test if it’s valid or not.

    jQuery:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"/>
    <script>
    
    function ValidateEmail(email)
    {
       var url = 'validateemail.php?email=' + email;
    
       $.getJSON( url, function(data) {
    
           var result = jQuery.parseJSON(data);
           var ctrl = $("#email_field");
    
           if(result.isValid == "true") {
               ctrl.addClass("valid").removeClass("inValid");
           }
           else {
               ctrl.addClass("inValid").removeClass("valid");
           }
       });
    }
    
    $(document).ready(function() {
    
         // change blur to keyup if you want it to validate as they type (bad idea)
         $("#email_field").bind("blur", function(){
             ValidateEmail($(this).val());
         });
    });
    
    </script>
    

    (not tested, but should give you the general idea)

    you’ll need a script called validateemail.php on your server – it should pick up the email parameter and then return either:

    {"isValid": "true"} or {"isValid": "false"}
    

    depending on the value of email.

    Easy way:
    Add two css classes to your page (valid and inValid) – when the page is submitted, if the email exists add the valid class to the input control, if it doesn’t add the invalid class instead.

    CSS:

    .valid { color: #ffffff; }
    .invalid { color: #ffebe8; }
    

    PHP:

    <input type="text" 
        name="email" 
        id="email_field" 
        onFocus="changeColorEmail(this)"
        <?echo 'class="'.(email_exists($_GET['email']) ? 'valid': 'inValid').'"';?>
    >
    

    try the second one first

    UPDATED: bug fixes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to style a form input[text] field, but I'm getting this white border
I'm trying to use this gem to create a honeypot field, but I'm not
I'm trying to add validation to a dynamic input field. What I'm doing is
I'm trying to get a button (input field or button field) value each time
I'm trying to build a control logic that depends on the current gsp page
I'm trying to figure out what logic should go into the different UIViewController methods
I'm trying to implement a reconnect logic for a wcf client. I'm aware that
I am trying to add some additional logic to the 'Promoted to front page'
I'm trying to develop business logic for a dynamic site using nusoap on server
I'm trying to figure out the logic for creating tasks that have dependencies. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.