volume one
volume one

Reputation: 7563

Is it acceptable to reuse Name and ID attributes across different Forms?

I have multiple Forms in my html page, each doing similar tasks but different enough to warrant having more than one form.

Each Form has its own unique ID of course. But the elements within the Form basically need to have the same ID and Name attributes e.g.

<input type="text" name="subject" id="subject">
<input type="submit" name="Submitt" id="Submit" value="Submit">

I need to use the above elements in many Forms (upto 5). It seems excessive to label each one uniquely just for the sake of it.

Is it 'acceptable' to have Form elements with the same ID and Name in different Forms, as long as each Form has its own unique ID and Name?

Upvotes: 1

Views: 1216

Answers (2)

Sridhar R
Sridhar R

Reputation: 20418

I Agree with above answer. Name is ok, and will be passed as response parameter of your form. if your input elements would have same id's as well - some browsers might have problems traversing dom of your document. so you may use same name but use different id's...

Upvotes: 1

David
David

Reputation: 4873

Having the same names is perfectly acceptable, if that's what the field is. ID's on the other hand are unique per page, so those need to be different. Remember, an ID is an ID, so having two would be like you sharing a social security number with somebody.

Edit: I'm not sure what you're using the IDs for, but if it's CSS, then just use classes.

Upvotes: 1

Related Questions