Copy link to clipboard
Copied
Ihave the following script I an placing in the custom calculation for text field "TrailerBodyTypeHideShow". My goal is to allow the user to make selections in previous radio buttons, but keep the two fields ( "TrailerBodyTypeTT" and "TrailerBodyTypeVT" hidden until either the user selected: whether or not the trailer will be fixed to the ground; and, whether the trailer is new or used; and, whether it has a FL title or OOS title. I keep getting an error message 'Syntax Error 10 at line 10'. Despite many attempted variations I continue to get this message. Here's the latest calc script used and I'm attaching the file also. I've been using Thom Parker's article "Hiding/Showing Fields" as a guide but I must be doing something wrong. Guidance is greatly appreciated- thanks in advance- kemper
var TTB = this.getField("TrailerTypeButtons").value;
var TLFXD = this.getField("TrailerFixedPermenantButtons").value;
var TLNUH = this.getField("TrailerNewUsedButtons").value;
var TLTIT = this.getField("TrailerTitleButtons").value;
if ((TTB != "VT") && (TLFXD != "") && (TLNUH == "New") || (TLTIT != ""))
this.getField("TrailerBodyTypeTT").display = display.visible;
this.getField("TrailerBodyTypeVT").display = display.hidden;
else if ((TTB == "VT") && (TLFXD == "") && (TLNUH == "New") || (TLTIT != ""))
this.getField("TrailerBodyTypeTT").display = display.hidden;
this.getField("TrailerBodyTypeVT").display = display.visible;
Copy link to clipboard
Copied
You are missing curly brackets {} after your both conditions.
Copy link to clipboard
Copied
It's because you're not using curly braces with the if statements. It should be:
var TTB = this.getField("TrailerTypeButtons").value;
var TLFXD = this.getField("TrailerFixedPermenantButtons").value;
var TLNUH = this.getField("TrailerNewUsedButtons").value;
var TLTIT = this.getField("TrailerTitleButtons").value;
if ((TTB != "VT") && (TLFXD != "") && (TLNUH == "New") || (TLTIT != "")) {
this.getField("TrailerBodyTypeTT").display = display.visible;
this.getField("TrailerBodyTypeVT").display = display.hidden;
} else if ((TTB == "VT") && (TLFXD == "") && (TLNUH == "New") || (TLTIT != "")) {
this.getField("TrailerBodyTypeTT").display = display.hidden;
this.getField("TrailerBodyTypeVT").display = display.visible;
}
Copy link to clipboard
Copied
Note that I did not analyse the code for correct logic, rather syntax only.
Copy link to clipboard
Copied
Thank you George and Nesa for your responses and guidance! Under what circumstances are the curly brackets required and why?
Copy link to clipboard
Copied
The "if" has no way to know that you want it to apply to two lines. Only you know that! So you put the brackets to tell it that this is the thing you want to apply to { thing ... thing ... thing } is just one thing because of the brackets.
Copy link to clipboard
Copied
If you always include the brackets, you don't have to worry about when they need to be used.