-
-
Save paulmaloney/5326415 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
<html> | |
<head> | |
<title>IE Placeholder Text</title> | |
</head> | |
<body> | |
<input type="text" name="myInputField" value="" placeholder="HTML5 Placeholder Text" id="myInputField"> | |
<!--[if IE]> | |
<script type="text/javascript"> | |
// A no-dependancy quick and dirty method of adding basic | |
// placeholder functionality to Internet Explorer 5.5+ | |
// Author: Jay Williams <myd3.com> | |
// License: MIT License | |
// Link: https://gist.github.com/1105055 | |
function add_placeholder (id, placeholder) | |
{ | |
var el = document.getElementById(id); | |
el.placeholder = placeholder; | |
el.onfocus = function () | |
{ | |
if(this.value == this.placeholder) | |
{ | |
this.value = ''; | |
el.style.cssText = ''; | |
} | |
}; | |
el.onblur = function () | |
{ | |
if(this.value.length == 0) | |
{ | |
this.value = this.placeholder; | |
el.style.cssText = 'color:#A9A9A9;'; | |
} | |
}; | |
el.onblur(); | |
} | |
// Add right before </body> or inside a DOMReady wrapper | |
add_placeholder('myInputField', 'IE Placeholder Text'); | |
</script> | |
<![endif]--> | |
</body> | |
</html> |
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
// A no-dependancy quick and dirty method of adding basic | |
// placeholder functionality to Internet Explorer 5.5+ | |
// Author: Jay Williams <myd3.com> | |
// License: MIT License | |
// Link: https://gist.github.com/1105055 | |
function add_placeholder (id, placeholder) | |
{ | |
var el = document.getElementById(id); | |
el.placeholder = placeholder; | |
el.onfocus = function () | |
{ | |
if(this.value == this.placeholder) | |
{ | |
this.value = ''; | |
el.style.cssText = ''; | |
} | |
}; | |
el.onblur = function () | |
{ | |
if(this.value.length == 0) | |
{ | |
this.value = this.placeholder; | |
el.style.cssText = 'color:#A9A9A9;'; | |
} | |
}; | |
el.onblur(); | |
} | |
// Add right before </body> or inside a DOMReady wrapper | |
add_placeholder('myInputField', 'IE Placeholder Text'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment