PDA

View Full Version : Resolved Using id vs. name in an HTML form



xtiano77
03-16-2009, 12:57 AM
Does the "$_POST['searchtype']" works with the 'name = "searchtype" ' or could it be used with the 'id = "searchtype" ' attribute? Thanks in advance for your help.

magicyte
03-16-2009, 01:02 AM
It will only work with name, but you can use both if you want. It makes no logical sense though. If you would like to, make sure there is no other element with the same id. Just to say, the id doesn't affect the outcome in any form or way.

xtiano77
03-16-2009, 01:16 AM
Thank you Chris for your prompt reply. I understand what you are saying about it not making sense. I was just trying to find out if it worked with the "id" attribute so I can write "Strict" XHTML if needed. Thanks again.

magicyte
03-16-2009, 01:29 AM
No, it doesn't work with the id attribute. Simple as that. I'd already said "It will only work with name", just to let you know.

Twey
03-16-2009, 02:44 AM
Names are used as the names of the parameters, and may be non-unique (to allow for checkbox groups, radio button groups, and element arrays); IDs are used to refer to the element within the document (e.g. from Javascript), and must be unique.

Probably you shouldn't be worrying about XHTML compatibility at the moment. IE doesn't yet support XHTML, so it is not feasible for most applications.