Skip to content

Instantly share code, notes, and snippets.

@chadmoone
Created December 20, 2012 01:30
Show Gist options
  • Save chadmoone/4342286 to your computer and use it in GitHub Desktop.
Save chadmoone/4342286 to your computer and use it in GitHub Desktop.
This script works well for all fields in IE9, but does not work for password fields in IE8.
unless Modernizr.input.placeholder
# if password input have to clone it as a text input and then remove this later (otherwise it will show up as ******)
# add focus state to remove this input and show / focus the original
$("[placeholder]").focus(->
input = $(this)
if input.val() is input.attr("placeholder")
input.val ""
input.removeClass "placeholder"
).blur(->
input = $(this)
if input.val() is "" or input.val() is input.attr("placeholder")
if input.attr("type") is "password"
newInput = input.clone()
newInput.attr "type", "text"
newInput.val input.attr("placeholder")
newInput.addClass "placeholder clone"
newInput.insertAfter input
input.hide()
newInput.focus ->
$(this).remove()
input.show().focus()
else
input.addClass "placeholder"
input.val input.attr("placeholder")
).blur()
$("[placeholder]").parents("form").submit ->
$(this).find("[placeholder]").each ->
input = $(this)
if input.hasClass("clone")
input.remove()
return
input.val "" if input.val() is input.attr("placeholder")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment