Hello,
I'm working on a form and I have a question pertaining to three fields: V1, V3, and V4. I want V4 to be able to be the product of V1 and V3, if those values are filled. If not, I want to be able to manually put a number into V4.
I've researched and tried various different if,then statements, but none seem to be working. Please help!
Thank you so much,
Amanda
How about using 2 fields, one calculated, and one for user entered value:
var v1 = this.getField('V1').valueAsString
var v2 = this.getField('V3').valueAsString
if (v1 == '' && v2 =='') {
this.getField('V4_UserEntry').display = display.visible
this.getField('V4_Calculated').display = display.hidden
} else {
this.getField('V4_UserEntry').display = display.hidden
this.getField('V4_Calculated').display = display.visible
}
Another idea would be to use a single field, and calculate the value in the format script. Try something like this to see if it works:
var v1 = this.getField('V1').valueAsString
var v2 = this.getField('V3').valueAsString
if (v1 == '' && v2 =='') {
event.target.readOnly = false
} else {
var prod = // ... do your calculation here
event.target.readOnly = true
event.value = prod
}
Thanks Mark!
Unfortuantely the single field calculation did not work.
The two field version is not working for me either, but I didn't know where to put what the calculation would be (V1*V3), so I tried a couple different places and it didn't look like it was working. What would you suggest?
Thank you!
This should work in the Custom Calculation script:
var v1 = this.getField('V1').valueAsString
var v2 = this.getField('V3').valueAsString
if (v1 == '' && v2 =='') {event.target.readonly = false
} else {
var prod = this.getField('V1').value * this.getField('V3').value
event.target.readonly = trueevent.value = prod
}
I was using the 'Format' script since it would retain the value the user has entered (the Calculate script will replace that value).
No dice. The math will work if field V1 and V3 are filled. However, if V3 is empty and I try to type something into V4 it will display '0' once I leave the field. The value that I do type into V4 will affect other values.
Basically V1*V3, when V3 is applicable, will create V4. Other times V4 will be a general number. V4 - V5 - V6=V7
The number I tested it with was 150.00 and it shows in V7, just not in V4. So that tells me the value is in the field, it is just not displaying...correct?
Another question, is there anyway to have V4 display the number with two decimal points?
I so very much appreciate all of your help with this!! :-)
Thank you so much!! I appreciate it.
I have one last request, hopefully.
Can you look over how I have typed the code? I keep getting a Syntax Error : unterminated string literal 3: at line 4. And I just can't see where the error is...I don't know if I have left off a parenthesis or what.
var v1=this.getField('V1').valueAsString
var v2=this.getField('V2').valueAsString
if(v2=="){
event.target.readOnly=false
}else{
var prod=this.getField('V1').value*this.getField('V3').value
event.target.readOnly=false
event.value=Math.round(prod*100)/100;
}
I would be careful using JavaScript's Math.round method since there are known issues with it working properly for all values.
Grade School Sample Files look at the Rounding test, it contains a document level funciton that does not suffer from the rounding error common in JavaScript.
North America
Europe, Middle East and Africa
Asia Pacific