How to calculate the number of row in a dynamic table | Community
Skip to main content
January 15, 2008

How to calculate the number of row in a dynamic table

  • January 15, 2008
  • 13 replies
  • 12871 views
Hi,

I've got a dynamic table where rows can be added by the user, in each row there's a checkbox cell. At the end of the table there's a "fixed" row where I have to count the number of the checked dynamic rows. How can I do that?



Thanks for your help.

Pascal.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

13 replies

December 3, 2008
Two things I see right away ....the 9: in the error message indicates the line number where the error occurred. The reformatting of your code in this dialog makes it impossible for me to know which is line 9. You can right mouse click in the script editor and use the Goto Line option to get to th eright spot. Note that it coudl be on the previous line as well.



Second in javascript a comparison between two thing sis done using doube equal signs (==) and an assignment statement is done using single equal sign(=). In your if statement you are assigning the string 2 to the Row.Function ...you are not comparing the two strings ....therefore the code inside your if statement will never be executed.



Paul
December 2, 2008
Paul,<br />When I use the Javascript Console it gives me the following message:<br /><br />missing ) after argument list<br />9:XFA:form1[0]:Diario[0]:Button3[0]:click<br /><br />But I can't find the place where I should add the missing )<br /><br />Here is my script again (as it is currently):<br />-----------------------------------------------------------------<br />var rowIM=form1.Diario.Clocking.Row1.instanceManager.count+2;<br />var a=0<br />for(var i=0;i<rowIM.count;i++) <br /><br />{<br /> <br /> if(xfa.resolveNode("form1.Diario.Clocking.Row1["+i"].Function").rawValue="2") <br /> {<br /><br /> a++; <br /><br /> } <br />}<br />Diario.NumericField1.rawValue=a<br /><br />-----------------------------------------------------------------<br /><br />Can you give me any clue?<br /><br />Thanks<br /><br />Fabricio BRAGA
November 24, 2008
If you are using Acrobat you can hit the Ctrl-J key to view the Javascript console. This will tell you if there is an error in your script.
November 21, 2008
So I added a NumericField outside the table with the following code:<br /><br />----- form1.Diario.NumericField1[1]::calculate: - (JavaScript, client) -----------------------------<br />//1. Determine how many rows you have<br />var rowIM=form1.Diario.Clocking.Row1.instanceManager.count;<br />// counter for the searched value<br />var foremanCount=0<br />//2. Build a for loop to loop through each row<br />for(var i=0;i<rowIM.count;i++) <br />{ <br /> //3. Test the value of the Function field for the value that you are looking for <br /> if(xfa.resolveNode("form1.Diario.Clocking.Row1[" + i "]").Function.rawValue ="Foreman") <br /> { <br /> foremanCount++; //Increase the counter<br /> } <br />}<br />this.rawValue=foremanCount<br />---------------------------------------------------------------------<br />What am I doing wrong? My NumericField remains blank no matter what...<br />Thanks
November 21, 2008
Whereever you need to know th enumber of rows.
November 21, 2008
Thanks Paul, I will try that.

Only have one question to get me started: Where should this scripiting go?
November 21, 2008
You will need code that does this:



1. Determine how many rows you have. you can use this command:



form1.Dario.Clocking.Row1.instanceManager.count();



2. Build a for loop to loop through each row. Your max value should be the count you just calculated.

3. Inside the for loop test the value of the Function field for the value that you are looking for. Assuming that the count is set to i, to get the value use:



xfa.resolveNode("form1.Dario.Clocking.Row1[" + i "]").Function.rawValue
November 21, 2008
Good Morning,

I have a similar issue. I have a dynamic table with a fixed header row, one row (instance) that can be added or removed "Row1"and a fixed footer row.

In my repeatable row I have one field with a dropdown list called "Function"(form1.Diario.Clocking.Row1[0].Function) that gives the user 5 choices. Every time the user adds a row he can make a different choice.



The user can choose the following options:

Foreman

Fitter

Welder

Journeyman

Apprentice



Using numeric fields outside the table I want to count how many times each of the functions above appears in the dynamic table so the user knows how many people he has in each function.



I can post my sample if you would tell me how to upload it.

Thanks for any insights.
Level 2
November 20, 2008
That does help - thank you so much Tom!
New Participant
November 20, 2008
Not so easy to do.



The above script relies on all of the checked fields being the same name, but with a different number in the array (e.g. entry[0], entry[1], entry[2]).



If your fields have different names you need to test each field individually (call each by their own name).



You can use the "==" expression to return a value of 1 if it is correct though, so something like:



{

count = (fieldName == "true") + (fieldSecondName == "false") + (fieldValue == 75);

}



Could return a value of 3 if all of the expressions are true.



Hope this helps,



Tom