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

Help with a variable script

pforms
Registered: Nov 17 2009
Posts: 87

I have a field that sums the total number of monthly contacts (tmc).
The optimal number of contacts is 90.
I am trying to have a script display in another box, the +/- value from the number 90.
This is what I have:
 
form1.BodyPage1.Load::enter - (JavaScript, client) -------------------------------------------
 
var tmc = (xfa.form.form1.BodyPage1.Contacts.rawValue);
var a = (tmc - 90);
if (a > 90){
this.rawValue = "+" + a ;}
else {this.rawValue = "-" + a ;}
 

I am getting a ( - ) sometimes when the total > 90.
 
I have posted the form here: http://www.filehosting.org/file/details/247961/Contacts3_1_.pdf

My Product Information:
LiveCycle Designer, Windows
pforms
Registered: Nov 17 2009
Posts: 87
I've abandoned the variable approach and am now working with:

---- form1.BodyPage1.Load::validate - (JavaScript, client) ----------------------------------------

if (Contacts.rawValue > "90")
{
this.rawValue = "+" + (Contacts.rawValue - 90);
}

if (Contacts.rawValue < "90")
{
this.rawValue = "-" + (90 - Contacts.rawValue);
}

endif

This works except I can't get the ( + ) sign to display
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You've got a few issues here.
- You've chosen some odd events in which to place the scripts. It seems that this should be a calculation script.
- Did you remove the "enter" event before adding the "validate" event?
- In the second post, at the end of the script. There is no "endif" keyword in JavaScript
- The comparison in the second post is lexical, meaning that Acrobat is comparing the numerical values of the individual characters against one another.
- The comparison should also be an if/else structure. The way you have it misses the case when the number of contacts is 90.
- Also in the second post, JavaScript evaluates the type of operation from left to right. Logically the mixed number/string statement should work out, but still, it's better to keep this bits explicit.
- try adding a ".toString()" to the numerical calculation
For example: (90 - Contacts.rawValue).toString();
- Validate events can be used for non-standard purposes, but the forms engine still expects this event to evaluate to true/false.
- The validate event is called when the value of a field is changed. Usually this event is used to validate user input. How is it getting called here?




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