PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________
Many thanks for your help Jim. To be honest this is beyond my current knowledge of JS but I guess this is the best way to learn. But having said that I haven't got it working yet - but I aint giving up!! Thanks again. Dave Marston. -----Original Message----- From: James Plante [mailto:[EMAIL PROTECTED] Sent: 02 September 2003 01:57 To: [EMAIL PROTECTED] Subject: Re: [PDF-Forms] Tricky calculations PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/ __________________________________________________________________ On Monday, Sep 1, 2003, at 10:20 US/Central, Marston, David wrote: > 1/ I have a series of form fields running down a column (over several > pages). What I need to do is to calculate the number of entries : ie - > if > there were 100 form fields in the column but data was only entered in > to 50 > of them (it could be text or numeric) the answer would be fifty. If > you are > familiar with Excel this is a "COUNTA" calculation. > So, it's not calculating the contents of the form field, only recording > whether the field has had anything entered into it. DISCLAIMER: This is not the only solution, and may not be the best solution. It is untested, so the code may require editing. It is intended to give you an idea of how to approach the problem. N.B.: Javascript is not as fast as Excel. It is an interpreter. Avoid JavaScript calculation scripts as much as possible; instead, do your calculations in validate, keystroke, or in custom document scripts which are activated by a control or a specific event. That being said, I hope you named the columns in that table according to the Acrobat Forms naming convention. Let's say you have the following column headers: Product, Group, Quantity, Price, ExtPrice. Name the fields which contain the values as Product.0, Group.0, Quantity.0, Price.0, and ExtPrice.0. Select all the fields in the first row; control-click (Mac) or right-click (Win), and from the contextual menu which appears, select "Duplicate multiple times". Make 99 more rows. Now the rows will be numbered from .0 to .99, enabling you to do this: function counta () // name the function something that you're familiar with var count = 0; // initialize a counter. for (var i = 0; i <= 99; i++){ // loop from 0 to 99 (100 times) a = this.getField("Quantity."+i).value; // grab the value out of Quantity.i ( "i" holds the number extension of the field) if a.length > 0 count +=1; // if the length of the string contained in the field is greater than 0, then count it by incrementing the counter. } return count You can put this in a document level script, and call it with a button's mouseup action; you can put it into a calculation script, but it'll bog down your sheet if you do; you can put it into a validate action in the quantity column, so that it fires when you leave the quantity column. Or, better yet, you can put it at document level and fire the script with the validate action, thus: counta(); Jim Plante <[EMAIL PROTECTED]> To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html To change your subscription: http://www.pdfzone.com/discussions/lists-pdfforms.html
