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

Multiple textfields calculating into one textfield

Outlander00
Registered: Jan 10 2011
Posts: 9
Answered

Hello,
 
First, I wanted to say that I am a noob when it comes to working with JavaScript (especially using it with LiveCycle/PDF applications); however, this community has helped a lot in my education on the topic.
 
I do have an issue that has thrown me for a loop, and hoping someone can point me in the right direction: I want to be able to take three text boxes and have them calculate into a fourth... however, I want to have either one calculate by itself, or the other two calculate together into the fourth. Is this possible? If so, where do I start? Ive exhausted my small amount knowledge and whatever reference material I have on hand
 
Any help is appreciated. Thanks in advance!
 

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
What do you mean by 'calculate'?
You can concatenate the values (combine text strings), add the values, multiply the values, etc.

Under what conditions would you use the only the first field?
Under what conditions would you use second and third field?

George Kaiser

Outlander00
Registered: Jan 10 2011
Posts: 9
I basically want to have the fourth box either display the .rawValue in the first box, or the combined .rawValue of the second and third box. Both conditions would be string values, just its an "either/or" scenario.

I've tried making this function work a few ways but, as I said, my knowledge in the subject matter is limited to what I have learned on my own in a short amount of time.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Accepted Answer
Computers and programs very seldom handle ambiguity correctly.

You need to use the 'if' statement to decide which fields to process and if the 2nd and 3rd fields are used then the 'Concat' function to join the values.

Without field names, it is pretty hard to provide exact code.

In FormCalc the calculation script for TextField4:

$.rawValue = null
if(TextField1.rawValue ne null) then
$.rawValue = TextField1.rawValue
else
$.rawValue = Concat(TextField2.rawValue, " ", TextField3.rawValue)
endif

The above assumes you want to use field 1 if it has any non-blank value.


George Kaiser

Outlander00
Registered: Jan 10 2011
Posts: 9
This worked... Thank you very much!