Link to home
Start Free TrialLog in
Avatar of debbieau1
debbieau1Flag for United States of America

asked on

How to change the colour of a text box when clicked

Can anyone tell me how to change the colour of a text box on a form, when it is clicked.  I am not sure if I needed to post this in the javascript area, or if it can be done in CSS which I would prefer.  

thank you

Debbie
Avatar of GrandSchtroumpf
GrandSchtroumpf

It cannot be done using CSS only.

<div onclick="this.style.color='red'">
hello world
</div>
Avatar of debbieau1

ASKER

Hi thanks for your quick response.

The hello world example worked great but I couldnt' get it to work on my text box.  I would be grateful if you could give me a little more help if you don't mind.

thank you very much

Debbie
> I couldnt' get it to work on my text box.
What's a text box?  You mean a form element of type text? or a textarea?

<input type="text" value="hello world" onclick="this.style.color='red'"><br>
<textarea onclick="this.style.color='red'">hello world</textarea>

Please post your code if this does not solve your problem.
sorry, here is my code (I have increased the points, which I hope makes up for the extra effort you are giving.

<input name="glossarybox" type="text" id="glossarybox" size="25">

I would like the background  or border to change colour when the tick box is clicked.  I have a css style applied to the default input box.

thank you for all your help

Debbie
 
ASKER CERTIFIED SOLUTION
Avatar of GrandSchtroumpf
GrandSchtroumpf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Exactly what I needed.  Thank you so much!!

Debbie