Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q717 How do you change the color of the text in a text box after an onChange?

You are here: irt.org | FAQ | JavaScript | Form | 1 | Q717 [ previous next ]

Try this:

<form>
<input type="text" onChange="this.style.color='red'">
</form>

The following was submitted by Jeff Gerew

The code below not only changes the text color to blue while you are 'focused', but it highlights the background of the textbox and/or text area.

// Add this to the head section of your page
<style type="text/css">
textarea.normal { background-color:FFFFFF }
textarea.hilite { background-color:FFFFCC;color:0000FF }
.textbox_normal { background-color:#FFFFFF; }
.textbox_hilite { background-color:#FFFFCC;color:#0000FF }
</style>

// use these properties for your text box(es)
<input type="text" name="textbox1" size="30" maxlength="40" class="textbox_normal" onFocus="this.className='textbox_hilite'" onblur="this.className='textbox_normal'">

<textarea name="textarea1" cols="100" rows="2" wrap="VIRTUAL" class="normal" onFocus="this.className='hilite'" onblur="this.className='normal'"></textarea>

Feedback on 'Q717 How do you change the color of the text in a text box after an onChange?'

©2018 Martin Webb