Just curious

Hello, everyone,

Just curious: If there are two or more radio or checkbox inputs with the same name, and if at least one radio/checkbox is checked, then they are treated as an array-like object. (ie, if they are named “status”, then they are referenced as document.forms['formname'].status[0] and document.forms['formname'].status[1]; higher if there are more.)

Does the same not apply to input type=“text”? If there are two text fields with the name of “status”, can they not be accessed with document.forms['formname'].status[0] and document.forms['formname'].status[1]??

V/r,

:slight_smile:

http://codepen.io/ryanreese09/pen/wBxLde

That’s what I thought, but I’m getting an error message that is confusing me.

I’ve got a script that (when a value 0 through 25 is chosen from a SELECT) will dynamically create x number of input text fields, all with the same name, and append them to a DIV.

As an afterthought, I wanted to set it up so that IF there are more than one inputs, the first of these input fields would get focus as soon as the script is done running.

FireBug says that document.getElementById('FCScode')[0] is undefined. I just created them in the DOM, even if they weren’t there on page load. Seems like it should be pretty straightforward.

V/r,

:slight_smile:

Technically can’t there ever be one of those elmeents though since it’s an ID? So I doubt it’s possible to have an array of them. That’s probably why you attempting to find the array of the ID is throwing an error.

1 Like

That was it. I’ve got it fixed for one of them (there are three). Now I just need to determine something else for the other two, and they’ll all work!

Thanks, @RyanReese!

:slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.