<html>
<head>
<title>Clear form field on initial focus</title>
<script type="text/javascript">
function clearOnInitialFocus ( fieldName ) {
var clearedOnce = false;
document.getElementById( fieldName ).onfocus = (function () {
if (clearedOnce == false) {
this.value = '';
clearedOnce = true;
}
})
}
window.onload = function() { clearOnInitialFocus('myfield');
</script>
</head>
<body>
<h1>Clear form field on initial focus</h1>
<input name="myfield" id="myfield" value="default message">
</body>
</html>
clear form field on first focus
Leave a Reply
You must be logged in to post a comment.