The script clears the form input field when the cursor is clicked on it. The script is made universally, it checks the default value and has no effect on the current value. I.e., when you click on the field again, it won’t be cleared.

<script type="text/javascript">
 //A script that clears the form of text when the cursor clicks on it
function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = "" } }
function doDefault(theText) { if (theText.value == "") { theText.value = theText.defaultValue } }
</script>

<p><INPUT type="text" name="textfield" size="40" maxlength="150"
	value="Enter your name"
	onFocus="doClear(this)"
	onBlur="doDefault(this)">
</p>
0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like