Copy link to clipboard
Copied
I have 3 text boxes involved in this code. the first text box is called adults, the second is called children and the third is called result. Once the user enters numbers into the first 2 textboxes the 3rd should display a result, and the result will be different depending on the numbers entered in the adults and children text boxes. here is the code that I wrote for it but it isn't working.
var a = this.getField("adults").value;
var b = this.getField("children").value;
if ((a == 1) && (b >= 5))
(event.value == "FSR")
else if ((a <= 2) && (b >= 8))
(event.value == "FSR")
else
(event.value == "PAU")
I have this code written in the "custom calculation" area of the result text box properties.
Also, change the first two lines to:
var a = Number(this.getField("adults").value);
var b = Number(this.getField("children").value);
Copy link to clipboard
Copied
What exact result do you expect, and what do you see? Looking at code we can't always deduce what you intended, only what it actually does. What errors if any do you see in the JavaScript console?
Copy link to clipboard
Copied
I expect for either the letters "FSR" or "PAU" to show up in the result text box.
what I see right now when I enter numbers into the "adults' and "children" text boxes is nothing. the "result" text box remains empty.
Copy link to clipboard
Copied
Use this:
if ( a==1 && b>=5 )
event.value = "FSR";
else if ( a<=2 && b>=8)
event.value = "FSR";
else
event.value = "PAU";
Copy link to clipboard
Copied
Also, change the first two lines to:
var a = Number(this.getField("adults").value);
var b = Number(this.getField("children").value);
Copy link to clipboard
Copied
thank you, that worked.
Copy link to clipboard
Copied
JavaScript has an "assignment" operator and 2 equality comparison operators and they are not interchangeable.
"=" is the assignment operator and used to assign a value to an object or variable.
"==" is the comparison operator and performs type conversion for the comparison.
"===" is the strict comparison and does not perform type conversion for the comparison.
Type conversion is usually converting Strings to Numbers.
Try the following corrected code in the Custom JavaScript code" calculation:
var a = this.getField("adults").value;
var b = this.getField("children").value;
if ((a == 1) && (b >= 5));
(event.value = "FSR");
else if ((a <= 2) && (b >= 8));
(event.value = "FSR");
else
(event.value = "PAU");
Copy link to clipboard
Copied
Ok, so how about the JavaScript console?
Copy link to clipboard
Copied
you mean, did I try having the code run on a mouse event?
I did try that and still nothing happens.
Copy link to clipboard
Copied
You can use the key combination of <Ctrl> + J.
Your console will show nothing. You are using the wrong operator for the assignment of a value.