Posted By

flicity on 01/19/10


Tagged

clear search jquery autfill


Versions (?)

autofill and clear text input


 / Published in: jQuery
 

URL: http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click/

add a value to your text input e.g. "Enter keywords" and clear on-click

  1. autoFill($("targetElement"), "content");
  2.  
  3. //auto fill search field
  4. function autoFill(id, v){
  5. $(id).attr({
  6. value: v
  7. }).focus(function(){
  8. if($(this).val()==v){
  9. $(this).val("").css({
  10. color: "#333"
  11. });
  12. }
  13. }).blur(function(){
  14. if($(this).val()==""){
  15. $(this).val(v);
  16. }
  17. });
  18.  
  19. }

Report this snippet  

You need to login to post a comment.