Reputation: 2802
Simple question. Is it possible to replace the following code:
document.form_name.element_name
with
document.form_name.<array[index].value>
?
Upvotes: 0
Views: 189
Reputation: 8402
assuming <array[index].value>
has "element_name" in it, you can do the following:
document.form_name[array[index].value]
Upvotes: 0
Reputation: 57729
var my_element = "username";
document.form_name[my_element];
and
var fields = [ "username", "realname" ];
document.form_name[fields[0]];
Upvotes: 0