PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________
Refer to the solution for Part I for the form fields naming setup and disclaimer. Let's name the columns referenced in this part "Summary.0" through "Summary.19". You want to count the number of "5" responses, the number of responses which were "4", etc., and there are only 20 surveys to analyze.
function SumIf()
var count = [0,0,0,0,0,0]; // initialize an array; six elements, each set at zero; (you won't use count[0] unless "0" is a response.
// N.B.: JS arrays are always indexed from zero.
for (var i = 0; i <= 19; i++){ // loop through all 20 responses
a = this.getField("Summary."+ i).value; // get whatever's in the summary field
count[a]++; // increment the array element which corresponds to that response
}
for (i=1; i<=5; i++){ // loop through the last five elements of the elements of the "count" array; (skip zero)
this.getField("Summary." + i).value = count[i]; // set each Summary field to its corresponding count value found in the array
}
Put this script at document level, and set a button for a mouseup action to fire it. NOTE: the reason I recommend against using such code in calculation scripts is that each time a calculated value changes, ALL the calculation scripts fire. Since JS so slow, it bogs down the performance of your form, and you start getting delays in responses every time you enter a value on the sheet. You <can>, however, try using a variant of these functions in calculation scripts to see how they work for you. (That would be a great way to learn better than to do so.)
As I stated in my disclaimer, this isn't necessarily the best solution, or even the only solution. It may not even work without some tweaking, since I haven't tested it. There are folks on this forum who are much better at JS coding than I am. Perhaps one of them will suggest a more elegant solution, or generalize it better. Try'em all, and see which one works the best for you.
On Monday, Sep 1, 2003, at 10:29 US/Central, Marston, David wrote:
2/ I have a column of form fields (let's say 20 for the purposes of this
exercise). Those 20 form fields will only contain a single number between
1-5 (each of these numbers is a code which represents a clients response to
a question). So, in the 20 form fields I may have 8 "5"s, 3 "2"s and 9 "4"s.
What I need to do is add up all the entries for the "5" code, or the "3"
code and so on. If you are familiar with Excel this is a "SUMIF"
calculation. The result will be displayed in a separate form field on
another page which will hold the told entries for each code.
Jim Plante <[EMAIL PROTECTED]>
To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html
