jquery : clear input text fields on click - BUT only once!


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

simply script to clear a text field (ie. a search field) ... but only does it once, just in case the user returns the field to type more...... USABILITY!


Copy this code and paste it in your HTML
  1. var clearedFields = new Array();
  2.  
  3. $(document).ready(function() {
  4. $(':text').click(function() {
  5. var field_name = $(this).attr('name');
  6. if (jQuery.inArray(field_name, clearedFields) < 0) {
  7. $(this).attr('value', '');
  8. clearedFields.push(field_name);
  9. }
  10. });
  11. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.