Wilfredo Turner
Wilfredo Turner

Reputation: 71

getting an error there is no attribute "placeholder" in xhtml strict 1.0

I realize that placeholder is html 5 i believe. Is there an alternative for placeholder?

I have to use xhtml strict 1.0 it's a requirement.

Upvotes: 0

Views: 1265

Answers (3)

user5340092
user5340092

Reputation:

xhtml DOES support placeholder because XHTML is a mix of XML & HTML. The function works but it won't validate because validation methods haven't caught up with new coding principles. Use this as an alternative which does validate;

<input type="text" onfocus="if (this.value==this.defaultValue) this.value = ''" onblur="if (this.value=='') this.value = this.defaultValue" value="your placeholder text here" />

Upvotes: 0

blex
blex

Reputation: 25659

It's very easy with this library.

Just include the library in the <head> tag of your page (you can also download the file):

<script type='text/javascript' src="https://cdn.rawgit.com/jamesallardice/Placeholders.js/master/dist/placeholders.min.js"></script>

And use a placeholder like you would normally do:

<input type="text" placeholder="I have a placeholder!"/>

JS Fiddle Demo

Upvotes: 1

Jacob McKinney
Jacob McKinney

Reputation: 31

You are correct, placeholder is new to HTML5 so it's not going to work in XHTML and there is no real equivalent. The only thing I could suggest is setting the "value" equal to the placeholder text, but then the user will have to delete the text before inputting their own.

The only other option would be to somehow mimic placeholder text using javascript.

Upvotes: 2

Related Questions