I wanted to pick one for consistency ( though i don’t think it matters ) and went with id….via document.getElementById().
no longer use
- name attributes for js access
- form array access
There are multiple posts on this…but just to make life easy and not think about it any more..I’m using ids only.
Are there any issues with this choice?
I don’t care so much about N5 and N6 and W3 specs.
Here are some similar posts:
Best Practice: Access form elements by HTML id or name attribute?
In case of usage of id for each form input when you have multiple forms with multiple inputs on one page you’ll should care about uniqueness of identifiers for each input.
So the identifiers could became long like “my-form-user-name” and “my-other-special-form-user-name”, etc.
So I would suggest to give an id to form element, retrieve the form by id and then refer to its elements by name. It’s easier to create unique and readable identifiers for a few forms than for 50 fields of 5 forms with 10 fields in each.
And probably the code will be more readable.
Fiddle
But if you’re using labels like in my example and want to use attribute
forin them to bind them to inputs, then you’ll need have identifiers for that inputs anyway.