Reputation: 462
I'm trying to sort out validation issues on a selection of forms. The main error that is cropping up is duplicate IDs on input elements like buttons.
This is the message:
Error: Duplicate ID my id.
From line 258, column 25; to line 258, column 96
This is an example of a button.
<input type="submit" name="Submit" id="Submit"/>
I know that the ID can sometime be used with JavaScript processing but does the ID affect the way the form handles the element in anyway? I've also got IDs on hidden input elements.
<input type="hidden" name="value" id="value" value="5"/>
Surly I shouldn't need to talk to them even with JavaScript and there's nothing to style if they are hidden? If we assume I'm not using script and just posting a standard form, would the IDs have any effect on it and so it would be safe to change them to make them unique or remove them?
Upvotes: 0
Views: 206
Reputation: 76
It's not a problem for your form, and browsers have never made it into a problem either.
Your IDE / editor is however right to complain about it, as it's not how they're supposed to be used.
But can it cause any harm? Normally not. Selecting the wrong element at worst.
QuerySelectorAll and CSS don't even care, but jQuery does:
Upvotes: 1
Reputation: 300
In theory, the id has no effect on how the parent form element handles inputs, this is done through the name
property which is passed to POST
or GET
.
If you are not including any Javascript libraries or referencing ID's in scripts of your own then you should be fine to change the ID's to uniquify them.
Upvotes: 1
Reputation: 463
The anserw is no - id attribute does not affect an form.
Your error is quite obvious. Somewhere in HTML structure, You defined two (or more) elements with same ID. Since I don't know what is in line 258 of Your file, I cannot help more than that.
Upvotes: 1