« Blog Home

§ Fake placeholders

Fake placeholders...

var placeholderSupport = 'placeholder' in document.createElement('input');

function fixPlaceholder(el) {
  if(!placeholderSupport) {
    el.value = el.getAttribute('placeholder');
    el.className = 'gray';
    el.onfocus = function() {
      if(this.value === this.getAttribute('placeholder')) {
        this.value = '';
        this.className = '';
      }
    }
    el.onblur = function() {
      if(this.value === '') {
        this.className = 'gray';
        this.value = this.getAttribute('placeholder');
      }
    }
  }
}

var st = document.getElementById('searchtext');
if(st) {
  fixPlaceholder(st);
}

last edited on January 9th, 2016 at 5:09 PM

Comments

No Comments Here. Add yours below!

Add your comment

Name:
Email: (Will not be displayed - Privacy policy)
Website:
Comments:
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)
 

« Blog Home


Oppuk gazed down at the creature in disgust.  Not only had it forced its barbaric name upon him, it smelled of floral aromatics, which the denizens of this world often applied to themselves in the mistaken belief that the natural scents of their bodies were noisome, while blatant artificial odors were somehow more acceptable.
Oppuk, The Course of Empire, Eric Flint & K.D. Wentworth