Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Last None Blank field in a group
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Last None Blank field in a group

 Post Reply Post Reply
Author
Tgean View Drop Down
New Member
New Member


Joined: 17 Jun 2016
Location: Germany
Points: 4
Post Options Post Options   Quote Tgean Quote  Post ReplyReply Direct Link To This Post Topic: Last None Blank field in a group
    Posted: 17 Jun 2016 at 9:43am
I am not an expert script writer but I am learning. My goal is, I have a group of fields "Item.1" to "Item.25" on the form. At the tops of the form I have a field named "Last". Last.value should = the last item listed in fields 1 -> 25. I have been working on this for weeks now and for some reason my code is not working. Here is a link to the PDF file http://drive.google.com/file/d/0BzsJJd_3je99dU9CQ1VlbTZ5cTA/view?usp=sharing 

Please help me make this work. Its driving me mad

The Code is written as a custom calculation script in the field named "Last".

{
var theResult = null;
for (var theIndex = 1; theIndex < 26; theIndex++)
{
    var theField = this.getField( "Item" + theIndex );
    if (theField.value) 
{
        theResult = theField.value;
    } else 
{
        break;
}
}
var show = this.getField("Last");
show.value = theResult
}
Back to Top
Sponsored Links


Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 617
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 10:22am
There are errors in your code. Check the JS console and you'll see them.
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 617
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 10:23am
There are also errors in the calculation scripts of other fields in your file. You have to solve all of them first.
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Tgean View Drop Down
New Member
New Member


Joined: 17 Jun 2016
Location: Germany
Points: 4
Post Options Post Options   Quote Tgean Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 10:36am
I have checked the console I am rather new at this and I dont really know what is wrong.  

TypeError: f is null
1051:byteCodeTool
TypeError: theField is null
6:AcroForm:Last:Calculate

I have no clue why.
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 617
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 10:41am
It's because you didn't spell the name of the fields correctly. In your code you're trying to access "Item1", "Item2", etc., but the actual field names are "Item.01", "Item.02", etc.

Here's the correct code to use:

var theResult = "";
for (var theIndex = 1; theIndex < 26; theIndex++) {
    var theField = this.getField( ((theIndex<10) ? "Item.0" + theIndex : "Item." + theIndex) );
    if (theField.value) {
        theResult = theField.value;
    } else {
        break;
    }
}
event.value = theResult;

The other issue is with the calculation of the Total field. You renamed the Value fields but didn't update it, so it's not working now.
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Tgean View Drop Down
New Member
New Member


Joined: 17 Jun 2016
Location: Germany
Points: 4
Post Options Post Options   Quote Tgean Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 11:15am
First off thank you so much for the help. Can you explain to me why this.getField( ((theIndex<10) ?. I dont understand the logic there. I am not saying your wrong, I just want to learn more. 
Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 617
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 11:18am
You need to read the whole thing:
this.getField( ((theIndex<10) ? "Item.0" + theIndex : "Item." + theIndex) );

Basically what it does is adds the additional "0" in front of the index in case number is smaller than 10, because your fields are named "Item.01", "Item.02", and not "Item.1", "Item.2"... Makes sense?
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
Tgean View Drop Down
New Member
New Member


Joined: 17 Jun 2016
Location: Germany
Points: 4
Post Options Post Options   Quote Tgean Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jun 2016 at 11:31am
Perfectly Thank you again for your help. As I said I am still very new at scripting. This little project tought me alot. 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.047 seconds.