Have prefilled value in input, clears onclick, need text to go from gray durning prefilled to black when user typing

Posted on 2008-11-07
Last Modified: 2012-05-05

Have prefilled input box, when user clicks the field is erased, when the user clicks in however the text stays the muted gray, need that to be gray text before and black text when the user entering.

<input type=\"text\" id=\"cartId\" value=\"04 1234 1234\" name=\"cartId\" class=\"required2\" onclick=\"this.value='';this.onclick=null;\">

// CSS

input.required2 {



Open in new window

Question by:vrmetro
    LVL 17

    Accepted Solution

    judging by the backslashes I'm assuming this was in a PHP variable.

    Here's what you need.
    <input type=\"text\" id=\"cartId\" value=\"04 1234 1234\" name=\"cartId\" class=\"required2\" onfocus=\"this.value='';\">

    Open in new window


    Author Comment

    That removed the text when someone tabs to the box, great!  

    But as above I have a class showing the text as light gray, when they start typing in the box it is light gray as well, I'd like the typed text to be black.

    Any thoughts?
    LVL 15

    Assisted Solution

    <input type=\"text\" id=\"cartId\" value=\"04 1234 1234\" name=\"cartId\" class=\"required2\" onfocus=\"this.value=''; this.className='required3';\">

    then write your css class of "required3" to style it how you want it

    Author Closing Comment

    Perfect!  Thank you.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now