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

Beginner - this.getField not invoked

msigsworth
Registered: Mar 1 2011
Posts: 5

Here is what I am using. This appears to work in other configurations for other form fields...but for this and two others they just don't want to calculate. No error messages, just nothing invoked.
 
if(this.getField("noweeks").value >= 104)
{
event.value = 185
}
else
{
event.value = 0
}
 
The current field is a number format.
The noweeks field is also a number format.
 
I would ideally like the else value to be "" and not 0...but I will take what I can get.
 
Just, why will this not calculate?

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This must be a calculation script on an AcroForm?

There's nothing obviously wrong. You checked the console window for errors?

If I've got it right so far then the next step is to add a console.println statement to the code to check that the calculation script is in fact executed, and that the value of "noweeks" is being acquired correctly.

like this:

var nNoWks = this.getField("noweeks").value;
console.println("No Weeks Value = " + nNoWks);

if(nNoWks >= 104)
{
... and the rest ...


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

msigsworth
Registered: Mar 1 2011
Posts: 5
There in lies the problem. I added what you suggested and the println is not executed.

var nNoWks = this.getField("noweeks").value;
console.println("No Weeks Value = " + nNoWks);

if (nNoWks >= 104)
{event.value = 185} else
{event.value = ""}

NOthing
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Try putting the console.println first, without the variable, just have it print some text.

So just to be clear, you checked the console window and nothing is being displayed?

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

msigsworth
Registered: Mar 1 2011
Posts: 5
The calculation script is getting executed. I put in the following in line12 script:

app.alert("Do you want to eat sardine salad?")

When I change the noweeks value, this message appears.

That leaves the following as the area of the issue:

var nNoWks = this.getField("noweeks").value;

if (nNoWks >= 104)
{event.value = 185} else
{event.value = ""}

Is it possible that it relates to different field types? Although they are both set as numbers.
msigsworth
Registered: Mar 1 2011
Posts: 5
Even tried this:

if (this.getField("noweeks").value > 104)
{app.alert("Do you want to eat sardine salad?")} else
{event.value = 1}

At 105 the message appears, at 103 it does not.

So it appears that it is the setting of the value that is the problem.

I am using event.value = 185.

What is wrong with that?
msigsworth
Registered: Mar 1 2011
Posts: 5
Kind of figured it out.

The subsequent control is this:

if (this.getField("line12").value = 0)
{this.getField("line13").value = this.getField("line11").value} else
{if(this.getField("line12").value > this.getField("line11").value)
{this.getField("line13").value = this.getField("line12").value} else
{this.getField("line13").value = this.getField("line11").value}}

When I deleted this and no other controls referred to line12...everything works. So why does this script affect the previous?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The comparison operator is "==", not "=".

This line is incorrect:
if (this.getField("line12").value = 0)

Replace it with:
if (this.getField("line12").value == 0)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The use of "=" in the "if" statement turned a comparison it into an assignment, which setup a conflict with the calculation script. The second script must also be later in the calculation order. You gotta watch the details;)

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script