Subject: html control with same id and name ???
Posted By: muklee Post Date: 10/21/2004 11:11:23 PM
If i have a form with multiple <input> tags, which all using the same id and name, what will happen if I call :


alert(document.form.inputName.value);


Is it possible to loop through all these <input> using javascript? And how to do that?

Thanks in advanced.

Reply By: joefawcett Reply Date: 10/22/2004 12:49:58 AM
I think you will get an error but it's possible it will give you the value of one of the inputs, which one who knows?
It's illegal to have two elements with the same id, names are allowed to be duplicated for radio buttons although browsers don't complain they just behave unpredictably.
In IE if you use document.getElementsByName(<elementName>) then you get a collection of similarly named elements, with getElementById you get the first object with that id. If you have multiple ID's and names I'm not sure what will happen, worse still it might be random.

I suggest you change the design.

--

Joe

Go to topic 21089

Return to index page 737
Return to index page 736
Return to index page 735
Return to index page 734
Return to index page 733
Return to index page 732
Return to index page 731
Return to index page 730
Return to index page 729
Return to index page 728