HTML5 Placeholder Input Fields Fixed with jQuery


jQuery Fix for All Browsers


$('[placeholder]').parents('form').submit(function() {
  $(this).find('[placeholder]').each(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
      input.val('');
    }
  })
});
Advertisements

2 thoughts on “HTML5 Placeholder Input Fields Fixed with jQuery

  1. In this case it will be clear only when you submit the form, real placeholder don’t act this way, better is to clear it on focus. Also this will not work if the user want to have the same text as placeholder. Better approach then using value of input is to put label with text, put it, using css, in the place of input text and hide it in focus event accordingly. You can also use modernizr to detect if the browser support placeholders.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s