autofill and clear text input


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

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


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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.