These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

code for clear form button

mikediana
Registered: Oct 31 2007
Posts: 9
Answered

I can clear a form OK but please do you have a suggestion for code that targets just one page of a series of forms.

My Product Information:
Acrobat Pro Extended 9.3.1, Macintosh
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
var iPage = 0; // This is your page number, it is 0-based, so page 1 is 0var sFields = new Array();for(var x=0;x<numFields;x++) {if(getField(getNthFieldName(x)).page.indexOf(iPage) > -1)sFields[sFields.length] = getNthFieldName(x);}if(sFields.length > 0)resetForm(sFields);

Or something like that...

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

mikediana
Registered: Oct 31 2007
Posts: 9
Jim

Thank you very much
I tried it but to no effect, probably because of my very limited JavaScript

The problem is sitting here if you have time
WBS 2812 and WBS 4811 Admin Form
http://www.mhmvr.co.uk/site/pdfprojectd.php
I can send you an un-enabled version
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
What error messages are you getting?

I get:
Quote:
getField(getNthFieldName(x)).page.indexOf is not a function
4:Console:Exec
getField(getNthFieldName(x)).page.indexOf is not a function
4:Console:Exec
undefined
I think the way the 'page' property is being used is not correct. From the doucmentation the 'page' method will return the page number for a single page or an array of pages for a field that appears more then once in the pdf. Also a 'number' type of value needs to be converted to string for use in many character string oprerations and an array should be 'joined' into a string for some string operations.
var iPage = 0; // This is your page number, it is 0-based, so page 1 is 0var aFields = new Array(); // array of fields names that are foundvar fNumFields = this.numFields; // number of fields on formvar sFieldName; // sting for field namevar sPageLoc; // string of page or pages field located onfor(x = 0; x < this.numFields; x++) {sFieldName = this.getNthFieldName(x); // get field name for i fieldoField =  this.getField(sFieldName); // get field object// test for single occurance of a fieldif(typeof oField.page == 'number')sPageLoc = oField.page.toString(); // convert number to string    // test for multiple occurance of a field  if(typeof oField.page == 'object')sPageLoc = oField.page; // convert array to string // some debugging helpconsole.println(sFieldName + ': ' + oField.value + ' appears on page: ' + oField.page);console.println(typeof oField.page)console.println('pages on:' + sPageLoc);console.println('match to page number: ' + sPageLoc.indexOf(iPage))// end of debugging help if( sPageLoc.indexOf(iPage) > -1)aFields[aFields.length] = sFieldName;}if(aFields.length > 0)this.resetForm(aFields);

George Kaiser

mikediana
Registered: Oct 31 2007
Posts: 9
I get exactly the same error message as you
Thank you for your assistance
Your code works well
However in the page I want to clear there are, of course, I now realise - duplicate fields of others in the set of forms. (The first page in the set is filled in and duplicates common fields in the rest including the page I want to clear). These are cleared by the code as shown by the debugger.
I can uncouple the duplicates on the page I want to clear - so no problem
Thank you very much for your assistance
Here is a section from the debugger
FirstName: 124124 appears on page: 1
number
pages on:1
match to page number: -1
FirstNameDuplicate: appears on page: 2,3,4,5,6,7,8,9,10,11
object
pages on:2,3,4,5,6,7,8,9,10,11
match to page number: 1
FurtherComments: asfasf appears on page: 9
number
pages on:9
match to page number: -1
FurtherInformation: asfasfasf appears on page: 10
number
pages on:10
match to page number: -1
Initial_Check_Date: appears on page: 3
number
pages on:3
match to page number: 0
L1_TOTAL: appears on page: 3
number
pages on:3
match to page number: 0
L2_TOTAL: appears on page: 3
number
pages on:3
match to page number: 0
L3_TOTAL: appears on page: 3
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Yeah, sorry about that, I don't know what I was thinking (I did say, "or something like that")... :)

I don't like the alternate code because if you are clearing page 1 it will clear any fields that appear on a page that contains 1 like page 10, for instance.

Anyway, just do this:
var iPage = 0; // This is your page number, it is 0-based, so page 1 is 0var sFields = new Array();for(var x=0;x<numFields;x++) {var pg = getField(getNthFieldName(x)).page;if((typeof pg == 'number' && pg == iPage) || (typeof pg != 'number' && pg.indexOf(iPage) > -1))sFields[sFields.length] = getNthFieldName(x);}if(sFields.length > 0)resetForm(sFields);

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

mikediana
Registered: Oct 31 2007
Posts: 9
Jim
Wow that works well too. Many thanks. I am stuck for choice.

Dare I ask another separate question or do I have to start another thread?
Here I go anyway it arose at a meeting yesterday. Can a button be created to add an extra A4 page to the current one with one large text field in it? I thought this was only possible in Lifecycle. Regards
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Not in the free Reader unless you have a Reader Extension.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

mikediana
Registered: Oct 31 2007
Posts: 9
Jim
Thank you. That idea will have to wait. Your help much appreciated anyway
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
From the Acrobat JavaScript API Reference version 8:
Quote:
This property behaves as follows in Adobe Reader:
●Setting this property in versions of Adobe Reader earlier than 5.1 generates an exception.
●For Adobe Reader 5.1 and 6.0, setting this property depends on Advanced Forms Feature document rights.
●For Adobe Reader 7.0, this property cannot be set under any circumstances
From From the Acrobat JavaScript API Reference version 9 :
Quote:
Prior to Acrobat 6.0, this method returned nothing. Now, spawn returns an object representing the page contents of the page spawned. This return object can then be used as the value of the optional parameter oXObject for subsequent calls to spawn.
It appears you may have to test the version of Reader being used and warn the user if an upgrade is needed.

George Kaiser