Set a properti of an array of objects

A

Alejandro Narancio

Hello my name is Alejandro and i've a question.
I need to make a functions with this characteristics:
- params: an array of strings with the names of components in a page
(for example, some inputs)
- body: i need to assign to the property readOnly the value true for
all the objects in the array

Anybody know how can i do this?

Thanks,

Alejandro
 
L

Lasse Reichstein Nielsen

I need to make a functions with this characteristics:
- params: an array of strings with the names of components in a page
(for example, some inputs)
- body: i need to assign to the property readOnly the value true for
all the objects in the array

Anybody know how can i do this?

There is a problem with this. *Names* of input controls are only
meaningfull in the scope of the form they are in. Two different forms
can have controls with the same names. That means that a *name* is not
necessarily unique for elements in a page. The id attribute should
give unique identifiers, but you don't always use those on input elements.

With that in mind, here is a function:
---
function setReadOnly(names,scope) {
scope = scope || document; // default to document
var hasGEBN = Boolean(scope.getElementsByName);
for (var i=0;i<names.length;i++) {
var elems = hasGEBN?scope.getElementsByName(names):
scope.all[names];
for (var j=0;j<elems.length;j++) {
elems[j].readOnly = true;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top