Posted By

Tamedo on 06/12/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


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 =""; } }

Posted By: sabithpocker on August 28, 2009

onClick="if(this.value=='name')this.value=' ';"

i have put a space between single quotes to show its not double quotes

Posted By: sabithpocker on August 28, 2009

the reverse of this on focus out if you want to be more interactive

You need to login to post a comment.