www.webdeveloper.com
Results 1 to 2 of 2

Thread: FOR Loop limitation in js

Hybrid View

  1. #1
    Join Date
    May 2013
    Posts
    4

    FOR Loop limitation in js

    Hi,
    I am using below code to color the cells of Grid1 based on value in Grid3 column everytime the form gets loaded. There are some 8840 rows in Grid3 and 260 in Grid1. Ideally the first FOR loop should execute for 8840 times but its only running till 2850 or something like that.

    Code:
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }
    
    
    addLoadEvent(function() {
    
    CurrnumRows = AuditClient.Grid1.GetNumberRows();
    LognumRows = AuditClient.Grid3.GetNumberRows();
    
    
    for ( var countlog=0;countlog<=LognumRows ;countlog++)
    {
    //alert(countlog);
    AuditClient.Grid3.GetCell(0,countlog);
    var Identifier = AuditClient.Grid3.CellGetText;
    
          for (var countCurr=0;countCurr<=CurrnumRows;countCurr++)
              {
    
               AuditClient.Grid1.GetCell(3,countCurr);
               var IdentifierCurr = AuditClient.Grid1.CellGetText;
    
     	  if (Identifier == IdentifierCurr)
                 {
    	  AuditClient.Grid1.GetCell(3,countCurr);
                   AuditClient.Grid1.CellSetBackColor(0xfbff00);
                    AuditClient.Grid1.CellSetReadOnly(1);
                    AuditClient.Grid1.SetCell(3,countCurr);
                    AuditClient.Grid1.RedrawAll();
                 }
          }
    }
    
    })
    Is it some sort of limitation in Javascript or I am making some mistake in the code? Please suggest.


    Thanks.
    Anil

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Try alerting LognumRows just before the start of the loop. Is it what you expected?

    Are you re-using those variable names anywhere else?
    You should make them local:
    Code:
    var CurrnumRows = AuditClient.Grid1.GetNumberRows(); 
    var LognumRows = AuditClient.Grid3.GetNumberRows();
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles