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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.