Posted By

wfdev on 04/02/08


Tagged

form javascript textmate clear search field accessible


Versions (?)

Search field content control


 / Published in: JavaScript
 

  1. //
  2. // Search form control function
  3. //
  4.  
  5. $(document).ready(function(){
  6.  
  7. // Get default search box value from hidden label
  8. $("#keywords").attr("value", $("#search label").text());
  9.  
  10. // Clear search box only if default value present
  11. $("#keywords").focus(function(){
  12. if ($(this).attr("value") == $("#search label").text()) {
  13. $(this).attr("value", "");
  14. }
  15. });
  16.  
  17. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wfdev on April 2, 2008

This takes the text content of a hidden label and populates the search input's value with it to save space and work in an accessible way.

When search input is focused on default text is removed.

Requires JQuery

You need to login to post a comment.