Clear a textfield when a user clicks on it (Rated 0)Description:
The trick is to only clear the textbox when the default text is displayed - so the user doesn't lose their input. This is done by comparing the value in the textbox and the value in a hidden field. Code starts here
<script>
function clearText(textElement, defaultElement)
{
if (textElement.value == defaultElement.value)
{
textElement.value = "" ;
}
}
</script>
<form name="myForm">
<input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText(this, document.myForm.defaultText);">
<input type="hidden" name="defaultText" value="Enter keyword here...">
</form>
Submitted by MattK on 06-01-2006 8:35 |