Click here to Skip to main content
13,141,157 members (53,932 online)

Nested for Loop not working for javascript.

Member 9410081 asked:

Open original thread
function SelectAccess(CheckBox) {
       var chkAc1 = document.getElementById('ctl00_MainContent_CheckBoxAccess').checked;
            if (document.getElementById('ctl00_MainContent_CheckBoxAccess').checked) {
                var ParentGrid = document.getElementById("<%= gvParentGrid.ClientID %>");
                if (ParentGrid.rows.length > 0) {
                    var chidgrid = $('#<%= gvParentGrid.ClientID %> table');
                    var chidgridVal = document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid');
                    if (chidgridVal.rows.length > 0) {

                        for (var j = 1; j < 11; j++) {
                            for (var i = 1; i <= chidgridVal.rows.length; i++) {
                               document.getElementById('ctl00_MainContent_gvParentGrid_ctl0' + (j + 1).toString() + '_gvChildGrid_ctl0' + (i + 1).toString() + '_ui_access').checked = true;
                               document.getElementById('ctl00_MainContent_gvParentGrid_ctl0' + (j + 2).toString() + '_gvChildGrid_ctl0' + (i + 1).toString() + '_ui_access').checked = true;

The above code for javascript but when the inside for loop gets executed the outer for do not get executed and j do not get incremented so for loop do not get executed completely.How to resolve this?My outer for loop executes at 1st time then inner for loop get executed till the lenght of rows, after execution of innner loop my j should get incremented and outer loop must get exceuted 1's again and then finally inner loop.
But my inner once executed do no go outside and exceution stops so only when value of j=1 the i increments and executed j 's value do not get incrmented.
Tags: Javascript, ASP.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100