Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Calling .val('') breaks placeholder functionality in certain scenarios #56

Closed
sbull opened this Issue · 1 comment

2 participants

@sbull

In IE, calling .val('') on an input field can break the placeholder functionality, depending on when the .val('') is actually called.

The following code demonstrates the bug.

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="jquery.placeholder.js"></script>
    <script type="text/javascript">
$(function(){
  $('input').placeholder();
  $('input').keydown(function(event){
    if (event.which === 13) {
      event.preventDefault(); // Silences bell, but not needed to demonstrate bug.
      $(this).val('');
    }
  });
});
    </script>
  </head>
  <body>
<form>
  Text: <input type="text" name="txt" placeholder="text holder"></input><br />
  Email: <input type="email" name="eml" placeholder="email holder"></input><br />
  Password: <input type="password" name="pwd" placeholder="password holder"></input><br />
</form>
<p>Press Enter in a Text or Email field to see the bug (in IE 9).</p>
  </body>
</html>
@sbull

My guess is that somehow the placeholder class doesn't get applied to the field again... perhaps it would be better to check the value of the field against the placeholder attribute in order to execute the placeholder functionality when the focus moves to a field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.