Jump to content

name attribute necessary?


lindm

Recommended Posts

In a form it often seems a waste of space with both the id and name attribute for a field, since they often are the same:

 

<input name="field" type="text" id="field" value="0" />

 

So far both have been necessary for a form submit and for instance if I also have javascript handling of the field. I have read that in xhtml id replaces name but can't get this to work. What would be nice is if the name attribute could be removed for a input field and when the form is submitted the id becomes part of the $_POST.

Link to comment
https://forums.phpfreaks.com/topic/188672-name-attribute-necessary/
Share on other sites

Actually the id in an input field is not necessary even though you're using Javascript

to refer to it, that could be done using :

 

document.forms[0].fieldname.value = "Field Value";

 

You can remove the id, and simply refer to it like that in Javascript,

and then in PHP,ASP, etc... you can refer to it with the name value.

 

PS : forms is an array so the '0' is referring to the first form field in the HTML file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.