Skip to main content
Participant
April 6, 2023
Question

Javascript: If AND statement to two text boxes

  • April 6, 2023
  • 1 reply
  • 833 views

Good morning, I have a form I'm looking at building where users will enter their age (between 45-75) and then check either male or female. At that point, it'll generate the cost of the product over both 10 years and lifetime. However, it's not working as it should. It recognizes the age but not the gender. Below is the script I'm using along with a screenshot of what I want it to look like. Thank you!

 

var e = event.value;
if(event.value){
if(e=="45"&&("gender"=="male")){
this.getField("10pay").value = "$12,000";
this.getField("pay100").value = "6,000";}
else
if(e=="45"&&("gender"=="female")){
this.getField("10pay").value = "$10,000";
this.getField("pay100").value = "$5,000";}
else

if(e=="46"&&("gender"=="male")){
this.getField("10pay").value = "$13,000";
this.getField("pay100").value = "$7,000";}

else

if(e=="46"&&("gender"=="female")){
this.getField("10pay").value = "$11,000";
this.getField("pay100").value = "$6,000";}
else{
event.rc = false;
this.getField("10pay").value = "Call 800-800-8000 for Support";
this.getField("pay100").value = "Call 800-800-8000 for Support";
}}

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
April 6, 2023

"gender" is not valid comparison, if your radio button group is named "gender" and they have export values of "male" and "female" then use like this:

var e = event.value;

var gender = this.getField("gender").valueAsString;
if(event.value){
if(e=="45"&&(gender=="male")){
this.getField("10pay").value = "$12,000";
this.getField("pay100").value = "6,000";}