a_********@hotmail.com (Alejandro Narancio) writes:
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[i]):
scope.all[names[i]];
for (var j=0;j<elems.length;j++) {
elems[j].readOnly = true;
}
}
}
---
You can call it as
---
setReadOnly(["foo","bar","baz"]);
---
or, if you know which form the controls are in,
---
setReadOnly(["input1","input2","input3"],document.forms['myForm']);
---
Good luck
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'