Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript: If AND statement to two text boxes

New Here ,
Apr 06, 2023 Apr 06, 2023

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";
}}

TOPICS
How to , JavaScript , PDF forms
664
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2023 Apr 06, 2023
LATEST

"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";}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines