Posted By

gbot on 03/09/08


Tagged

forms prefill


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gbot
SpinZ


form input prefill clearer and reset


 / Published in: JavaScript
 

  1. // form input prefill clear on focus, and reset on blur (if empty)
  2.  
  3. function prefillClear(field) {
  4.  
  5. if (field.defaultValue==field.value) {field.value = '';}
  6.  
  7. else if (field.value == '') {field.value = field.defaultValue;}
  8.  
  9. }
  10.  
  11. // usage
  12.  
  13. <input type="text" name="input1" value="Enter your data" onfocus="prefillClear(this);" onblur="prefillClear(this);" />
  14.  
  15. // suggest using some further javascript to parse all input fields and apply these functions on domReady. This would save having to put the function calls inline.

Report this snippet  

You need to login to post a comment.