Advertisement
sbenjamin

JQuery: Clear Default on Click.

Jul 28th, 2011
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Steven Benjamin
  2. //www.stevenbenjamin.com
  3. //July 28 2011
  4. //Open Source Initiative OSI - The MIT License (MIT)
  5.  
  6. jQuery(document).ready(function() {
  7.  
  8.     //add listeners to the search string.
  9.     jQuery("#textBox").click(clearDefaultValue);
  10.     jQuery("#textBox").blur(resetDefaultValue);
  11.    
  12.     //clear the defaultValue on click.
  13.     function clearDefaultValue(e){
  14.         if (window.console) {console.log('clearFBArtistSearch :',e.currentTarget.defaultValue,e.currentTarget.value)};
  15.         if(e.currentTarget.value === e.currentTarget.defaultValue){
  16.             e.currentTarget.value = '';
  17.         };
  18.     };
  19.    
  20.     //replace the defaultValue if blank.
  21.     function resetDefaultValue(e){
  22.         if(jQuery.trim(e.currentTarget.value) === ''){
  23.             e.currentTarget.value = e.currentTarget.defaultValue;
  24.         };
  25.     };
  26.  
  27. }); //jquery ready
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement