Forms on Websites

Post Reply
James Hatts
Posts: 309
Joined: Sat 16 Aug, 2003 23.34
Location: London

add

onfocus="this.blur()"

to the text input
SteveL
Posts: 81
Joined: Fri 22 Aug, 2003 18.47

If you want to, you can make it so that if the user doesn't enter anything in the box the text re-appears after they click off it, by adding the below to the text box:

onBlur="if(this.value==''){this.value='Text';}" onFocus="if(this.value=='Text'){this.value='';}"

(Change Text to the initial text the box will be displaying).
Asa
Posts: 60
Joined: Fri 15 Aug, 2003 12.02
Location: South East England

Can anyone go one stage further and have it so the text is initially a light grey but changes to black when someone clicks/starts typing in the box?

Cheers, Asa
User avatar
Andrew Wood
Posts: 279
Joined: Fri 15 Aug, 2003 23.24
Location: Location: Location
Contact:

Asa wrote:Can anyone go one stage further and have it so the text is initially a light grey but changes to black when someone clicks/starts typing in the box?

Cheers, Asa
<pre><style type="text/css">
#a {color: #999999;}
</style>
<form>
<input type="text" id="a" length="30" onBlur="this.style.color='#999999';if(this.value==''){this.value='Text';}"
onFocus="this.style.color='#000000';if(this.value=='Text'){this.value='';}"><br>
</form>
</pre>

Regards,
Andrew
Post Reply