We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

Tamedo on 06/12/08


Tagged


Versions (?)


Text box OnClick event to remove default data


Published in: JavaScript 


  1. <html><head><title>(Type a title for your page here)</title>
  2.  
  3. <script type="text/javascript">
  4. function make_blank()
  5. {
  6. document.form1.type.value ="";
  7. }
  8. </script>
  9.  
  10. </head>
  11. <body >
  12.  
  13. <form name=form1 method=post action='test.php'>
  14. <b>Type</b><input type=text name=type value='Enter your user id' onclick="make_blank();">Enter User ID
  15. <input type=submit value=Submit> </form>
  16.  
  17. </body>
  18. </html>

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: _Undefined on June 12, 2008

This will remove whatever is in the text box every time the user clicks on it?

Posted By: romanos on June 12, 2008

Yes.

Here is a better way, no function needed:

... onclick="this.value='';">Enter User ID...

Posted By: kandutech on August 1, 2008

I modded the script a bit for my search box... Here it is:

function make_blank() { if(document.form1.q.value!="DEFAULT VALUE HERE") { } else { document.form1.q.value =""; } }

You need to login to post a comment.