Posted By

jimbo on 03/14/11


Tagged

form field


Versions (?)

Clear HTML Form Field on Entry


 / Published in: JavaScript
 

Clear a field on entry if the default text matches a supplied value. Generic to any field.

  1. function activate_field(field,txt)
  2. {
  3. if (field.value === txt) {
  4. field.value = "";
  5. }
  6. else { $(field).select(); }
  7. }
  8.  
  9. /*
  10.  * call with an onfocus event
  11.  * example:
  12.  * <input type="text" onfocus="activate_field(this,\'City\')"
  13.  * id="city" name="city" value="City" />'
  14.  */

Report this snippet  

You need to login to post a comment.