I need a way to accumulate a unique list of form element names.
I have a solution, but since I am a “part-timer” when it comes to javascripting,
I’d welcome comments or alternatives solutions.
Problem:
As far as a know, the javascript array object does not have a unique() method and adding
one thru prototype enlists probably some sort of nested loop. So here is my idea:
code is untested.
[code]
var names = {} FormName=”myform”,formelement;
var theform = document[FormName]
for(i=0; i<theform.elements.length; i++){
names[theform.elements[i].name] = 1; // arbitrary and boolean true
}
// now by iterating thru names with the in operator we have unique names?
for(var name in names) formelement = theform[name];
I repeat, the code is untested, but is my logic sound or is there a better way?
thanks
tim