tags:

views:

161

answers:

3

I'm trying to cleanup my xhtml validation -- I'm running my pages through the W3C validator. For some puzzling reason it's not passing on input fields with the autocomplete="off" attribute:

<input name="kwsearch" id="sli_search_1" type="text" autocomplete="off" onfocus="if(this.defaultValue==this.value) this.value='';"
            onblur="if(this.value=='')this.value=this.defaultValue;" class="searchbox" value="Search" />

I'm using this doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

And this is the validation error:

Line 410, Column 81: there is no attribute "autocomplete"

…li_search_1" type="text" autocomplete="off" onfocus="if(this.defaultValue==thi…

I thought this was okay with the W3C -- but, maybe it's still in "submission" phase? http://www.w3.org/Submission/web-forms2/#autocomplete

Thoughts?

+1  A: 

That W3C link is for the web forms stuff, not core XHTML. It might be possible to pull in the extra DTD for the web forms and get the page to validate.

Pointy
+1  A: 

autocomplete is a HTML5 attribute, so use a HTML5 document type declaration, if you need it.

toscho
+2  A: 

The Web forms specification has nothing to do with HTML 4 / XHTML. Sadly, autocomplete will not pass validation.

I think the only way to achieve valid HTML 4 /XHTML with autocomplete turned off is adding the attribute on page load using JavaScript. Sucks, I know - but I think it's the only way.

Pekka
Is page load early enough so that the browser hasn't filled in the form yet? I can remember reading an article on dynamically adding `autocomplete`, unfortunately I can't remember what the conclusion was.
Boldewyn
@Boldewyn damn good question! The consensus seems to be onDOMLoad, at least according to this: http://avatraxiom.livejournal.com/97999.html
Pekka