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

multiply three or more numeric fields

josephjohnson
Registered: Apr 26 2010
Posts: 5
Answered

HI,

This is probably quite simple. I am just getting started with LiveCycle and I am a bit frustrated.

I want my form to multiply three numbers. I don't care whether I use FormCalc or Javascript.

I want the results field to calculate as I put in the three numbers. I can only make the result show AFTER all three numbers have been entered. I do not want that. I want the result to show as soon as two numbers are entered and I want the result to change whenever I enter the third number.

Result = num1 * num2 * num3 does not work because it always WAITS for the last number to be entered before showing me the results.

This must be easy. It works progressively with addition, why not with multiplication?

Many Thanks

Joseph S. Johnson
joseph [dot] johnson [at] acegroup [dot] com

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What are initial values of the input fields? (if a number is multipled by zero then the result is zero) What is the result you are seeing? Are the fields set to be Number Fields?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jonom
Registered: Jan 31 2008
Posts: 133
josephjohnson wrote:
Result = num1 * num2 * num3 does not work because it always WAITS for the last number to be entered before showing me the results.This must be easy. It works progressively with addition, why not with multiplication?
I think you'll find that it is working with multiplication but multiplying by zero gets you zero.

You would have to come up with logic that would skip fields from the equation if they are equal to zero, or maybe makes the value of the field 1 until it is something else.
josephjohnson
Registered: Apr 26 2010
Posts: 5
HI Thom,

I am not really a programmer, but I dabble. I was able to write some code that did what I wanted.

form1.testing_subform.results::ready:layout - (JavaScript, client)

var firstnum;
var secondnum;
var thirdnum;
if (first.isNull) firstnum = 1; else firstnum = first.rawValue;
if (second.isNull) secondnum = 1; else secondnum = second.rawValue;
if (third.isNull) thirdnum = 1; else thirdnum = third.rawValue;
if (firstnum * secondnum * thirdnum == 1) this.rawValue = 0; else this.rawValue = firstnum * secondnum * thirdnum;

This is kinda headed in the direction of your post...trying to cope with zeroes. So, thanks for your thoughts.

The ironic part is...now that I have it...I don't want it. I decided to just go with "calculate" buttons instead.

Thanks again,
Joe

Joseph S. Johnson
joseph [dot] johnson [at] acegroup [dot] com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Realize that a no input value is a null value and that value is treated like zero. The following FormCalc script will detect null values and display the value as a string value.
// test input values for null valuevar num1Str = num1if (num1.rawValue eq Null) thennum1Str = "Null"endif

var num2Str = num2if (num2.rawValue eq Null) thennum2Str = "Null"endif

var num3Str = num3if (num3 eq Null) thennum3Str = "Null"endif

// compute resultvar result = num1 * num2 * num3 // build messagevar sMsg = "Input values:"sMsg = Concat(sMsg, "\u000D num1: ", num1Str, "\u000D num2: ", num2Str, "\u000D num3: ", num3Str) // compute resultvar result = num1 * num2 * num3var sResult = resultif(result eq "") thensResult = "Null"endif

sMsg = concat(sMsg, "\u000d result: ", sResult)// display messagexfa.host.messageBox(sMsg) // fill in field valueresult

George Kaiser

jonom
Registered: Jan 31 2008
Posts: 133
Josephjohnson: that's along the lines of what I just came up with to test it out.

var a = Num1.rawValue;var b = Num2.rawValue;var c = Num3.rawValue; if (Num1.rawValue == null) {a = 1;}if (Num2.rawValue == null) {b = 1;}if (Num3.rawValue == null) {c = 1;} var d = a * b * c; if (d == 1) {this.rawValue = 0;}else {this.rawValue = d;}