I'm trying to give placeholder workaround for IE7, IE8, and IE9. From the codes on the internet, I found the javascript, and I try to test it using simple page like this:
<html>
<HEAD>
<script type="text/javascript">
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
</script>
</head>
<body>
<form>
<input class="placeholder" type="text" name="nama" placeholder="try">
</form>
</body>
</html>
which I hoped will show an input with placeholder text "try" inside on IE 8. but it's not showing anything. I've tried anything I can try outside the javascript code, like erasing the class attribute, adding complete attribute to the form tag, and else. but the placeholder still seems not shown. can you help me what's wrong with this code? I'm still new with javascript and web programming, so maybe the mistake is not immediately apparent to me.
I got the code from https://gist.github.com/hagenburger/379601