8 Replies Latest reply on Sep 9, 2011 2:39 AM by jmcpolin_2000

    Javascript For loop not working within a function

    jmcpolin_2000 Level 1

      Hi all,

       

      I'm a beginner to LiveCycle and I cant seem to get a loop working within a function.  The function is being called successfully because when I manually create the code it works but I am trying to clean things up.

       

      So here is my working example:

       

      function hideContent() {

              MainFlowedSub.LevelsSub.Table1.presence = "hidden";

              MainFlowedSub.LevelsSub.Table2.presence = "hidden";

             ... and so on....


               MainFlowedSub.LevelsSub.Table8.Row1.presence = "hidden";

              MainFlowedSub.LevelsSub.Table8.Row2.presence = "hidden";

             ... and so on....

      }

       

      However when I try and creat a loop instead of listing every sing table/row nothing happens. this is important to my project as there will be alot of different rows depending on radio button selections earlier in the form.  Below is the current state of my code:

       

      function hideContent() {

       

          var i=0;
           for (i=1;i<=5;i++)
           {
               MainFlowedSub.LevelsSub.Table[i].presence = "hidden";
           }

       

          var j=0;
           for (j=1;j<=23;j++)
           {
               MainFlowedSub.LevelsSub.Table8.Row[j].presence = "hidden";
           }

       

          var k=0;
           for (k=24;k<=88;k++)
           {
               MainFlowedSub.LevelsSub.Table8.Row[k].presence = "hidden";
           }

      ;

       

       

      this will then continue as there will be hundreds of rows.

       

      Any help will be greatly appreciated and I am sure I am making a basic error  so thanks in advance.

      j

        • 1. Re: Javascript For loop not working within a function
          pguerett Level 6

          You cannot use square brackets in javascript as it thinks you are referring to an array. So you have to use a different notation

          xfa.resolveNode("string that references the object")

           

          So in your case the reference woudl be:

           

          xfa.resolveNode("MainFlowedSub.LevelsSub.Table[" + i + "]").presence = "hidden"

           

          Also note that each reference within the for loop will be an i not a j or k etc .....each time you run through the loop the value of i increases by 1 and the reference will be correct for your object.

           

          Make sense?

           

          paul

          • 2. Re: Javascript For loop not working within a function
            jmcpolin_2000 Level 1

            thanks for your help paul.  Again, really appreciated as I know very little about all this.

             

            Unfortunately its still not working... One thing I am sure of is that I am doing something very basic wrong. So here is my code, I have applied your suggestion above which will cover all my data:

             

            To give an understanding, I have 5 tables of content, each has i amount of rows. and I am running this script to clear/remove all items being displayed.

             

            function hideContent() {

             

                for (var i=1;i<=5;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table[" + i + "]").presence = "hidden";
                }

             


                for (var i=1;i<=71;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table8.Row[" + i + "]").presence = "hidden";
                }

             

                for (var i=1;i<=93;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table9.Row[" + i + "]").presence = "hidden";
                }

             

                for (var i=1;i<=99;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table10.Row[" + i + "]").presence = "hidden";
                }

             


                for (var i=1;i<=101;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table11.Row[" + i + "]").presence = "hidden";
                }

             

                for (var i=1;i<=87;i++)
                {
                    xfa.resolveNode("MainFlowedSub.LevelsSub.Table12.Row[" + i + "]").presence = "hidden";
                }

             

            }

             

            It has to be something to do with my For loops because if I manually insert each line it works perfectly.

             

            Thanks again,

            johnny

            • 3. Re: Javascript For loop not working within a function
              pguerett Level 6

              Send me the form and I will have a look (LiveCycle8@gmail.com) include a description of the issue in the email.

               

              Paul

              • 4. Re: Javascript For loop not working within a function
                jmcpolin_2000 Level 1

                Thanks Paul,

                 

                I have send you an email, hopefully I have explained myself.

                 

                Again, thanks for your time!

                johnny

                • 5. Re: Javascript For loop not working within a function
                  pguerett Level 6

                  Didn't see anything from you yet.

                   

                  Paul

                  • 6. Re: Javascript For loop not working within a function
                    jmcpolin_2000 Level 1

                    Sorry I am unsure what happened there. I have resent the email to LiveCycle8@gmail.com

                     

                    thanks,

                    j

                    • 7. Re: Javascript For loop not working within a function
                      pguerett Level 6

                      Still nothing ......is the gmail site being filtered on your end?

                       

                      Paul

                      • 8. Re: Javascript For loop not working within a function
                        jmcpolin_2000 Level 1

                        Hi Paul,

                         

                        Apologies about the delays in communication.  Email issue was a problem on my end beyond my control.

                         

                        Thank you for your support, it has been most appreciated and my issue is now resolved. For anyone else reading, I have posted an example of the resolved code.

                         

                         

                        function show_number_algebra() {       
                            var i=0;
                            for (i=1;i<=27;i++)
                            {
                                xfa.resolveNode("MainFlowedSub.LevelsSub.Table8.Row" + i).presence = "visible";
                            }   
                        }

                         

                        function show_number_algebra() {       
                             var i=0;
                             for (i=28;i<=64;i++)
                             {
                                 xfa.resolveNode("MainFlowedSub.LevelsSub.Table8.Row" + i).presence = "visible";
                             }   
                        }

                         

                        etc. etc.