/ Published in: JavaScript
Expand |
Embed | Plain Text
<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>
Comments
Subscribe to comments
You need to login to post a comment.

This version depends on Prototype.js.
This no longer depends on Prototype. Why I'm typing comments on my own code, instead of just editing the description, I don't know.