Skip to content

Instantly share code, notes, and snippets.

@GoodProject
Created April 13, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoodProject/0200563f9e9b76d3751c0b97fa5cbdc6 to your computer and use it in GitHub Desktop.
Save GoodProject/0200563f9e9b76d3751c0b97fa5cbdc6 to your computer and use it in GitHub Desktop.
<!--[if IE 9]>
<script type="text/javascript">
(function setPlaceHolders(){
var input = document.getElementsByTagName('input'); // get all text fields
var cls = "placeholdr"; // set name of the class
if (input) { // if fields found
for (var i=0; i < input.length; i++) {
var t = input[i];
var txt = t.getAttribute("placeholder");
if (txt.length > 0) { // if placeholder found
t.className = t.value.length == 0 ? t.className+" "+cls : t.className; // add class
t.value = t.value.length > 0 ? t.value : txt; // if no value found
t.onfocus = function() { // on focus
this.className = this.className.replace(cls);
this.value = this.value == this.getAttribute("placeholder") ? "" : this.value;
}
t.onblur = function() { // on focus out
if (this.value.length == 0) {
this.value = this.getAttribute("placeholder");
this.className = this.className+" "+cls; // add class
}
}
}
}
}
})();
</script>
<![endif]-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment