Use Modernizr to add a value attribute to enter email

Affect the syntax a bit. I have an email in which placeholder text is set. To maintain backward compatibility, I use Modernizr to add a Value attribute for input, but without any success.

Ideas? Thank you for your help!

HTML:

<input type="email" name="email" id="email" class="corners" placeholder="Enter your email address" />

JavaScript:

if (!Modernizr.input.placeholder){
  setValue(document.getElementById('email'),'Enter your email address');
}
+3
source share
1 answer

My initial thought was that lack of placeholder support could be a problem when manipulating values โ€‹โ€‹of type = "email". When setting up fast jsFiddle, I was able to successfully update the value (testd in IE7).

setValue makePlaceholder .

function makePlaceholder( el, placeholder ) {
    el.onfocus = function(){
        if( placeholder == el.value ) {
            el.value = '';
        }
    };
    el.onblur = function() {
        if( '' == el.value && placeholder != el.value ) {
            el.value = placeholder;
        }
    };
    el.value = placeholder;
}

, , .

+1

All Articles