Advertisement
nucklear

Add placeholders to Fkng! IE input forms with modernizr

Jun 17th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function ($) {
  2.  
  3.             // check placeholder browser support
  4.             if (!Modernizr.input.placeholder)
  5.             {
  6.  
  7.                 // set placeholder values
  8.                 $('form').find('[placeholder]').each(function()
  9.                 {
  10.                     if ($(this).val() == '') // if field is empty
  11.                     {
  12.                         $(this).val( $(this).attr('placeholder') );
  13.                     }
  14.                 });
  15.  
  16.                 // focus and blur of placeholders
  17.                 $('[placeholder]').focus(function()
  18.                 {
  19.                     if ($(this).val() == $(this).attr('placeholder'))
  20.                     {
  21.                         $(this).val('');
  22.                         $(this).removeClass('placeholder');
  23.                     }
  24.                 }).blur(function()
  25.                 {
  26.                     if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))
  27.                     {
  28.                         $(this).val($(this).attr('placeholder'));
  29.                         $(this).addClass('placeholder');
  30.                     }
  31.                 });
  32.  
  33.                 // remove placeholders on submit
  34.                 $('[placeholder]').closest('form').submit(function()
  35.                 {
  36.                     $(this).find('[placeholder]').each(function()
  37.                     {
  38.                         if ($(this).val() == $(this).attr('placeholder'))
  39.                         {
  40.                             $(this).val('');
  41.                         }
  42.                     })
  43.                 });
  44.  
  45.             }
  46.  
  47. ......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement