Copy link to clipboard
Copied
Hello!
I am very new at using Adobe and I am trying to make a pre-filled interactive adobe form. I have the boxes communicating/calculating from each other.
For example I have a Fahrenheit box which has a Celsius box that calculates from the answer entered in the Fahrenheit box. The problem I am having is when Fahrenheit is not applicable during certain uses of the form, the Celsius box is still answering -17.8° which is equal to 0°F, which the form is assuming is the answer since nothing has been typed in. I need the box to not compute when don't have an answer to enter in.
Can anyone let me know the best solution for my problem?
Thank you!
1 Correct answer
First, stop an think about this. What is the numeric value of a null string or mull?
Many programs treat as zero. And this is exactly what JavaScript does if left to itself.
Fortunately most computer languages and scripting languages have conditional statements and some properties, statements or methods that tell the difference between a null string and zero. This type of coding requires custom JavaScript coding.
I assume you do not want to suppress zero results.
For the Celsius box (text field) you
...Copy link to clipboard
Copied
First, stop an think about this. What is the numeric value of a null string or mull?
Many programs treat as zero. And this is exactly what JavaScript does if left to itself.
Fortunately most computer languages and scripting languages have conditional statements and some properties, statements or methods that tell the difference between a null string and zero. This type of coding requires custom JavaScript coding.
I assume you do not want to suppress zero results.
For the Celsius box (text field) you need to create a custom JavaScript calculation that uses the conditional "if" statement to test if the Fahrenheit field entry is a null string and not zero.
/ default Celsius result to null sring;
event.value = "";
// get field object for Fahrenheit field;
var oFahrenheit = this.getField("Fahrenheit");
// test if field value string is null;
if(oFahrenheit.valueAsString != "")
{
// compute conversion only if Fahrenheit value not null;
event.value = (oFahrenheit.value - 32) * 5 / 9;
} // end of value not null;
Copy link to clipboard
Copied
Hello,
Thank you for your response, I just have a couple other questions. When I put your suggestion in my custom calculation form it gives me:
SyntaxError: unterminated regular expression literal
1: at line 2
This is the code I had in the box previous to your suggestions in case that helps to figure out the issue :
function calculateCelsius(){
return (this.getField("Flash_Point_F").value - 32) * 0.5555;
}
event.value = calculateCelsius();
Also I call my Fahrenheit box "Flash_Point_F" and I call my Celsius box " Flash Point (C)
If you could give a suggestion as to where to go from here I would really appreciate it!
Copy link to clipboard
Copied
The error message must be coming from something else. That script works fine.
Copy link to clipboard
Copied
Do you have any idea what the error message could be coming from? I copied and pasted the exact script.
Copy link to clipboard
Copied
Probably from an incorrect use of the "/" symbol.
Copy link to clipboard
Copied
I think I see the problem.. In the code above there's a missing "/" in the beginning of the first line.
Copy link to clipboard
Copied
(I was testing your code before, not the one provided by George...)
Copy link to clipboard
Copied
Yes!!! That worked! Thank you so much I have been working on this for a while now
Have a great day!
Copy link to clipboard
Copied
The first line should start with "//" not "/".
if I were to write this as a function, I would pass the degrees Fahrenheit as a parameter and not access the field within the function. That would make the code independent of any fields and it could be used any time when this conversion is needed in other forms. The function definition would be placed at the document level so its scope would be the entire form. You then only need 5 lines in the custom calculation script option. I also used the fraction to avoid any issues because of a truncated decimal value.
function DF2C(nFerienht)
{
return (nFerienht - 32) * 5/9;
} // end DF2C function;
// custom calculation script;
var oFlashPoint = this.getField("Flash_Point_F");
event.value = "";
if(oFlashPoint.valueAsString != "") {
event.value = DF2C(oFlashPoint.value);
}

