Jump to content

Lag in while loop


Thierry

Recommended Posts

I have a while loop (4096 is the minimum amount) which goes through a long list of cells.

Although saving 4096 cells is do-able, when it gets more, the browser thinks the script has gotten stuck and it takes forever to finish it.

 

In the loop, all it does is get the table cell ('with frames["framename"].document.getElementById(tile_counter)') and then get a style from it and checks a few things with the result.

When a result matches a certain thing, it will update a field with the value.

I'll end up with a hidden field having a lot of values separated by commas. (green,black,yellow,red,purple etc)

 

When I removed the getElementById part the script was finished instantly, so I'm geussing using 4096 getElementById's is what is causing the lag.

 

Is there another way of getting the table cell without causing much lag? I only need the style.backgroundColor attribute.

Link to comment
https://forums.phpfreaks.com/topic/59634-lag-in-while-loop/
Share on other sites

i'm not sure i get your problem. are you saying you're changing the background color of every <td></td> cell in a table and there are 4,096 cells?

 

if so, might I ask, why not just set the background color for the entire table?  that would be 1 css action instead of 4,096. --never mind:

 

maybe you could post a snippet of code, i'm not sure what you're trying to do.

Link to comment
https://forums.phpfreaks.com/topic/59634-lag-in-while-loop/#findComment-297563
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.