<!DOCTYPE html> <html> <head> <script language="javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".someClass").each(function() { var $this = $(this); var defaultVal = $this.attr("title"); $this.focus(function() { if ($this.val() === defaultVal) { $this.val(""); } }); $this.blur(function() { if ($this.val().length === 0) { $this.val(defaultVal); } }); }); }); </script> <style> input { display:block; margin-bottom:5px; } </style> </head> <body> <input type="text" value="Name" /> <input type="text" value="Email Address" /> <input type="text" value="Insert form refill here" /> </body> </html>
<!DOCTYPE html> <html> <head> <script language="javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".someClass").each(function() { var $this = $(this); var defaultVal = $this.attr("title"); $this.focus(function() { if ($this.val() === defaultVal) { $this.val(""); } }); $this.blur(function() { if ($this.val().length === 0) { $this.val(defaultVal); } }); }); }); </script> <style> input { display:block; margin-bottom:5px; } </style> </head> <body> <input type="text" value="Name" /> <input type="text" value="Email Address" /> <input type="text" value="Insert form refill here" /> </body> </html>