Created
April 13, 2017 18:15
-
-
Save GoodProject/0200563f9e9b76d3751c0b97fa5cbdc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--[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