Posted By

jimbo on 03/14/11


Tagged

form html validation field


Versions (?)

Fill Any Empty HTML Field on Exit with a user supplied value


 / Published in: JavaScript
 

Often you supply a default value in a text field which you want to automatically clear when the user enters the field. This will do that operation and fill the field with a default value.

  1. function no_empty(field, text) {
  2. if( field.value == "")
  3. {
  4. field.value = text;
  5. }
  6. }
  7.  
  8. /* call with an onblur event
  9.  * example:
  10.  * <input type="text" maxlength="24" onblur="no_empty(this, \'City\')" id="city" name="city"
  11.  * value="City" />'
  12.  */

Report this snippet  

You need to login to post a comment.