Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.
Instead, use this:
HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
  $('input').each(function(i,v){
      // set initial values
      $(this).val($(this).attr('placeholder'));
           console.log($(this).val());
  });
});
 
$('input').on({
     'click': function(){
           if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
      },
     'blur': function(){
           if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
     }
});

And all is good and right in the world.
I'm assuming you have a basic understanding of document structure and how to implement jQuery.
If you have any questions, please ask.

Similar Posts