Expand my Community achievements bar.

Counting Checkboxes with different Names

Avatar

Former Community Member
I have a form that I am creating in Livecycle Designer 8.0 that has 100 checkboxes that the user selects from. I would like to have a field that counts how many check boxes are checked. What is the easiest way to do this?



Also, Do I have to add each field individually or is there a way to select them all and insert to the formula at once?



Thanks!
3 Replies

Avatar

Former Community Member
You can write a script that will query the number of objects in the form. Once you have that you can get each object one by one and see which type of object it is. If it is a checkbox you can see if it is checked or not. If checked then you can add it to your counter. If you send me your form I will incorporate it into a button event for you to see.

Avatar

Former Community Member
send me the form,will get it working for you

mergeandfuse@gmail.com

Avatar

Former Community Member
Big thanks out to Paul Guerette for helping me write the script for this. He gave me an option to do it as an exit event of the pages or on a button click. Here is the code for the button click:



- form1.Order_Page.Button1::click: - (JavaScript, client) ---



form1.Order_Page.Product_Table.Row3.Course_Quantity.rawValue = 0;



//app.alert("Page1 Exit Event fired!!!!");

//Get total number of element on Page 1 of the form

var allChildElements = form1.Course_Selection_Subform1.Course_Selection_Page_1.nodes;

var intNumElements = allChildElements.length;



//app.alert("The number of elements is: " + intNumElements);



//Loop through all the objects on Page1

for(j=0; j< intNumElements;j++){

//set the 1st object to a variable name

currentElement = allChildElements.item(j);



//if the object is a field then test to see if it is a checkbox

if(currentElement.className == "field") {

//app.alert(currentElement.ui.oneOfChild.className);

// is it a checkbox?

if (currentElement.ui.oneOfChild.className == "checkButton"){

//Is the checkbox checked?

if (currentElement.rawValue == "1"){

//increment the Course_Quantity field

form1.Order_Page.Product_Table.Row3.Course_Quantity.rawValue = form1.Order_Page.Product_Table.Row3.Course_Quantity.rawValue + 1;

}

}

}



}



//app.alert("Page2 Exit Event fired!!!!");

//Get total number of element on Page 1 of the form

var allChildElements = form1.Course_Selection_Subform2.Course_Selection_Page_2.nodes;

var intNumElements = allChildElements.length;



//app.alert("The number of elements is: " + intNumElements);



//Loop through all the objects on Page1

for(j=0; j< intNumElements;j++){

//set the 1st object to a variable name

currentElement = allChildElements.item(j);



//if the object is a field then test to see if it is a checkbox

if(currentElement.className == "field") {

//app.alert(currentElement.ui.oneOfChild.className);

// is it a checkbox?

if (currentElement.ui.oneOfChild.className == "checkButton"){

//Is the checkbox checked?

if (currentElement.rawValue == "1"){

//increment the Course_Quantity field

form1.Order_Page.Product_Table.Row3.Course_Quantity.rawValue = form1.Order_Page.Product_Table.Row3.Course_Quantity.rawValue + 1;

}

}

}

}