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


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.