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

Hello,

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.

Thanks,
<input type=\"text\" id=\"cartId\" value=\"04 1234 1234\" name=\"cartId\" class=\"required2\" onclick=\"this.value='';this.onclick=null;\">
 
// CSS
input.required2 {
	color:#CCCCCC;
}

Open in new window

vrmetroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nplibCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vrmetroAuthor Commented:
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?
0
MMDeveloperCommented:
<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
0
vrmetroAuthor Commented:
Perfect!  Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.