Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3.         <title>IE Placeholder Text</title>
  4.        
  5. </head>
  6.  
  7. <body>
  8.  
  9. <input type="text" name="myInputField" value="" placeholder="HTML5 Placeholder Text" id="myInputField">
  10.  
  11. <!--[if IE]>
  12. <script type="text/javascript">
  13. // A no-dependancy quick and dirty method of adding basic
  14. // placeholder functionality to Internet Explorer 5.5+
  15. // Author: Jay Williams <myd3.com>
  16. // License: MIT License
  17. // Link: https://gist.github.com/1105055
  18.  
  19. function add_placeholder (id, placeholder)
  20. {
  21.         var el = document.getElementById(id);
  22.         el.placeholder = placeholder;
  23.  
  24.     el.onfocus = function ()
  25.     {
  26.                 if(this.value == this.placeholder)
  27.                 {
  28.                         this.value = '';
  29.                         el.style.cssText  = '';
  30.                 }
  31.     };
  32.  
  33.     el.onblur = function ()
  34.     {
  35.                 if(this.value.length == 0)
  36.                 {
  37.                         this.value = this.placeholder;
  38.                         el.style.cssText = 'color:#A9A9A9;';
  39.                 }
  40.     };
  41.  
  42.         el.onblur();
  43. }
  44.  
  45. // Add right before </body> or inside a DOMReady wrapper
  46. add_placeholder('myInputField', 'IE Placeholder Text');
  47.  
  48. </script>
  49. <![endif]-->
  50. </body>
  51. </html>