Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid HTML to use input elements without id and name attribute only?

I'm reworking a site which uses inputs like this multiple times throughout a page:

 <input type="text" name="delDate" value="06.03.2012" />

There's always an adjacent hidden input, which gives the date enterted above a specific id, when the form is submitted, but I'm wondering if doing it like this (and omitting an input#id is a valid way doing things, since the W3C validator does not complain about it.

Thanks for some input!

like image 566
frequent Avatar asked Mar 06 '12 17:03

frequent


2 Answers

Yes, that is valid. The id attribute is not required.

like image 126
alex Avatar answered Nov 15 '22 07:11

alex


The problem of doing this is not that it is a validity problem but that it creates an accessibility problem (i.e., it may confuse screen readers for disabled users). It is generally considered best to have a label with a "for" attribute that matches the "id" attribute of the associated input element.

like image 34
Edward Avatar answered Nov 15 '22 09:11

Edward