views:

309

answers:

3

I need to get all the input objects and manipulate the onclick param.

the following does the job for links. looking for something like this for input tags.

for (var ls = document.links, numLinks = ls.length, i=0; i<numLinks; i++){
             var link = unescape(ls[i].href);
             link = link.replace(/\\'/ig,"#");
             if(ls[i].href.indexOf("javascript:") == -1)
             {
             ls[i].href = "javascript:LoadExtern(\\""+link+"\\",\\"ControlPanelContent\\",true,true);";
             }
            }
+2  A: 
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
  // ...
}
Pointy
+2  A: 

You can get a NodeList of all of the input elements via getElementsByTagName (MDC, MSDN), then simply loop through it:

var inputs, index;

inputs = document.getElementsByTagName('input');
for (index = 0; index < inputs.length; ++index) {
    // deal with inputs[index] element.
}
T.J. Crowder
+1  A: 

Or to do this slightly more efficiently,

var inputs, i;

for(i = 0; current = document.getElementsByTagName('input')[i]; i++) {
    // current will contain the currently selected element
}
Pawel J. Wal
That's very *inefficient*. You have him calling `getElementsByTagName` repeatedly (as many times as there are matching nodes).
T.J. Crowder