?
Solved

Highlight and Unhighlight Form Field

Posted on 2003-03-17
3
Medium Priority
?
1,039 Views
Last Modified: 2012-08-14
Here is bobbit13's code to highlight the strError:

if(!validateEmailv2(objValue.value))
              {
                if(!strError || strError.length ==0)
                {
                   strError = " Please enter a valid email address. ";
                   objValue.style.background = "#XXXXXX"; // choose color
                }//if                                              
                alert(strError);
                return false;
              }


But I would like the background to change back to #FFFFFF if the strError is corrected.  I suspect the easy way to do this is to change the background back to white when the user clicks on the "ok" button of the alert, or when the user onClicks inside this text field again to correct the problem.  The validation will run again and change the text field back to yellow if still incorrect.

0
Comment
Question by:champ_010
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 400 total points
ID: 8154385
first way (after ok is pressed):

                if(!strError || strError.length ==0)
                {
                   strError = " Please enter a valid email address. ";
                   objValue.style.background = "#XXXXXX"; // choose color
                }//if                                              
                alert(strError);
                objValue.style.background = "#FFFFFF";
                return false;

0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8154410
second way:

  <input type=text onfocus="this.style.background='#FFFFFF';">

or you could do it onchange

  <input type=text onchange="this.style.background='#FFFFFF';">
0
 
LVL 1

Author Comment

by:champ_010
ID: 8154464
Thanks bobbit31,

I like the first way.  I actually tried that before posting, but didn't work--probably because of a typo!--I've done that so many times before, but still haven't learned!  Glad you showed me.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question