Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change text box onmouseover

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
Hello.
How can I change the backgroun colour of a textbox within a form when there is a mouseover event?

Also, when the user actually clicks on said box, to make the default data in it dissappear.
For example, I have a textbox within a form titled email with a default value of "Not applicable". When the mouse moves over this box, I want the colour to change. And when the user clicks on the box, I would like the value "Not applicable" to clear so that the user can type his/her email :)

Please!
 
The following should do the trick. It has a global variable set up so that the input field for the email address is only cleared once (from it's initial value):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Untitled</title>

<script type="text/javascript">
function HighlightBackground(obj,color) {
	obj.style.backgroundColor = color;
}
var emailCleared = false;
function ClearInput(obj) {
	if (!emailCleared) {
		if (obj.name = "email") {
			obj.value = "";
			emailCleared = true;
		}
	}
}
</script>

</head>
<body>
<form name="theForm">
<input onclick="ClearInput(this)" onmouseover="HighlightBackground(this, '#ffeeee');" onmouseout="HighlightBackground(this, '#ffffff');" name="email" type="text" value="Not applicable">
</form>
</body>
</html>

Hope this helps.

Pete.

Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top