Link to home
Start Free TrialLog in
Avatar of plq
plqFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Slow javascript loop..

Any ideas how to speed this up ?

I've tried the easier option of running thru maintable.all but thats even worse. Its a long table in a scrollable div

1. Is there a way of doing a bulk change to many elements at once
2. Is there some kind of doevents function in js that will allow the user to continue working as it runs ?
3. Any other thoughts on speeding it up ?

function doedit()
{
      var ctl;

      var ctltypes = new Array("SELECT", "INPUT", "TEXTAREA");

      // perf improv over scanning all tags
      for (var c = 0; c < ctltypes.length; c++)
      {
            for (var k = 0; k < maintable.all.tags(ctltypes[c]).length; k++)
            {
                  ctl = maintable.all.tags(ctltypes[c])[k];
                  if (ctl.disabled)
                  {
                        ctl.disabled = false;
                  }
            }
      }
}


thanks
SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of justinbillig
justinbillig

try document.getElementsByTagName
Avatar of plq

ASKER

Hmmm dont know whats going on here

function doedit()
{
      var ctl;

      var ctltypes = new Array("SELECT", "INPUT", "TEXTAREA");

      // perf improv over scanning all tags
      for (var c = 0; c < ctltypes.length; c++)
      {
            var ctls = maintable.parentElement.getElementsByTagName(ctltypes[c]);
            for (var k = 0; k < ctls.length; k++)
            {
                  ctl = ctls[k];
                  if (ctl.disabled) ctl.disabled = false;
            }
      }
}

keeps saying getElementsByTagName is undefined?

Yet the msdn sample runs ok on my machine

Browser is ie6
Avatar of plq

ASKER

hold on...
Avatar of plq

ASKER

OK it works

But not substantially faster. I think the drag must be on setting .disabled.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plq

ASKER

Quite weird actually

Theres about 7000 controls with the tag types we want. This is an xml data bound table, so only one control at design time per field

It takes about one minute using the latest proposal above. But after the js function has exited (its called off a button), the browser locks up for another minute, and no js is running (I can prove that from breaking the net2003 debugger). Then the page finally comes back with the controls enabled.

Its obviously a design problem in having that many controls, but you'd hope there was a way of enabling them a bit faster.

I'm going to try enabling the whole table or its wrapper div to see if that works.
Avatar of plq

ASKER

Thats worked. table elements seem to support the disabled tag

but select elements as usual cause problems and are enabled, I can work around that.

I'll just split points as I appreciate everyones attempt to help on this..

thanks
You are welcome.