0

I am using HTML5 for one of my project. There I am using input placeholder property to show some default text. It's not working in IE. Any solution for this?

Deepak Biswal
  • 4,280
  • 2
  • 20
  • 37
  • 1
    possible duplicate of [Input placeholders for Internet Explorer](http://stackoverflow.com/questions/5522164/input-placeholders-for-internet-explorer) – Joshua Dwire Aug 05 '13 at 17:36

7 Answers7

3

If you are using javascript in your project, you can add this peace of code and it will provide a placeholder through javascript to your inputs.

function supports_input_placeholder() {
        var i = document.createElement('input');
        return 'placeholder' in i;
    }

if (!supports_input_placeholder()) {
    var fields = document.getElementsByTagName('INPUT');
    for (var i = 0; i < fields.length; i++) {
        if (fields[i].hasAttribute('placeholder')) {
            fields[i].defaultValue = fields[i].getAttribute('placeholder');
            fields[i].onfocus = function () { if (this.value == this.defaultValue) this.value = ''; }
            fields[i].onblur = function () { if (this.value == '') this.value = this.defaultValue; }
        }
    }
}
António Regadas
  • 714
  • 4
  • 11
  • Yes, that correct. But when you post the form you have to check at the server end also as it will have some value as per above code. – Deepak Biswal Aug 05 '13 at 17:50
  • @DeepakBiswal inputs with attribute `placeholder` don't imply any kind of server-side activity: the above code will take whatever has been put as the `placeholder` attribute and make that behaviour work in non-supporting browsers. It solves your problem! – Barney Aug 06 '13 at 10:37
2

Placeholder is not supported until IE 10.

http://caniuse.com/#feat=input-placeholder

You can use a polyfill to support it in IE.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

See the top answer on this thread as it has a very good explanation: Input placeholders for Internet Explorer

Community
  • 1
  • 1
Dawson Loudon
  • 6,029
  • 2
  • 27
  • 31
0

Older version of IE don't support html placeholders. Therefore, you will need to use a javascript solution like Placeholder.js. It automatically detects the placeholder attributes in your input elements and utilizes a cross-browser solution to show them.

amb110395
  • 1,545
  • 13
  • 16
0

Use jQuery placeholder. HTML5 placeholder is not supported by standard HTML5 declaration until Internet Explorer 10.

Barney
  • 16,181
  • 5
  • 62
  • 76
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53
  • w3schools is often inaccurate, reductive and misleading and shouldn't be propagated as a reference (Google does that already). http://www.w3fools.com/ – Barney Aug 06 '13 at 10:39
  • I know. I suggested him on a light way. Thank you for your tip. – Marin Sagovac Aug 06 '13 at 10:51
0

try Placeholders.js

it is light weight and also works well in IE 6

Mohammed Sufian
  • 1,743
  • 6
  • 35
  • 62
0

Alternative option would be to show the "name:" text on IE < 10

<!--[if lt IE 10]><style>.show-ie{display:block;}</style><![endif]-->
fourroses
  • 93
  • 1
  • 3
  • 15