Posts Tagged ‘textbox background’

Set textbox background color when clicked

To set the background color of the textbox, use the ‘backgroundColor’ property.
eg.

<input type="text" style='background:#fce09a' value='www.fordevs.com'>

If you want to set the background color on text focus then use the ‘onfocus’ event.

The following example illustrates you how to set the color in ‘onfocus’ event. When the texbox loses the focus then normal background color is retained.

<html>
<body>
<br><input class="searchInput" id="searchtextbox" onblur="this.style.backgroundColor='#ffffff';"
onfocus="this.style.backgroundColor='#fce09a';value=''" accesskey="s" value="[Enter your name]" name="searchtextbox" autocomplete="off"> <br>
<br>
</html>

Demo link

Popularity: 7% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars