Nested if statement and radio button issues
I am having some issues with my nested if statements. I currently have a form with two sections. The first section has a choice of client type (Individual, Joint, Corporation) which then opens corresponding fields. The person filing out the form has a choice of three radio buttons, because a client can only be one of the three types. For example, for an individual client:
var v=this.getField("InvestorType").value;
if (v=="Individual"){
this.getField("I").display=display.visible;
this.getField("J").display=display.hidden;
this.getField("C").display=display.hidden;
}
else if (v=="Joint"){
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
this.getField("C").display=display.hidden;
}
else {(v=="Corp");
this.getField("I").display=display.hidden;
this.getField("J").display=display.hidden;
this.getField("C.CorpType").display=display.visible;
}
This part of the code seems to be working great. Later in the form the investor has to answer a yes or no question (must check yes for legal reasons) however, the sections that open in the form are dependent on the type of client they selected previously (Individual, Joint, Corp.) I started with the No radio button, as I am fairly new to java. With just the No part was working great. I then moved onto the Yes portion. Here is what I have:
var v = this.getField("Accr_InvYN").value;
var x = this.getField("InvestorType").value;
var y = this.getField("CorpType").value;
if (v == "Yes" && x =="Individual"){
this.getField("I.Province").display=display.visible;
this.getField("I.FName").display=display.visible;
this.getField("I.Surname").display=display.visible;
this.getField("I.Sign").display=display.visible;
this.getField("S").display=display.visible;
this.getField("J").display=display.hidden;
this.getField("C").display=display.hidden;
this.getField("AOff").display=display.hidden;
this.getField("Acc_Inv").display=display.visible;
}
else if (v == "Yes" && x == "Joint"){
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
this.getField("C").display=display.hidden;
this.getField("S").display=display.visible;
this.getField("AOff").display=display.hidden;
this.getField("Acc_Inv").display=display.visible;
}
else if (v == "Yes" && x == "Corp"){
this.getField("I").display=display.hidden;
this.getField("J").display=display.hidden;
this.getField("C").display=display.visible;
this.getField("S").display=display.visible;
this.getField("AOff").display=display.hidden;
this.getField("Acc_Inv").display=display.visible;
}
else {(v=="No");
this.getField("I").display=display.hidden;
this.getField("J").display=display.hidden;
this.getField("C").display=display.hidden;
this.getField("S").display=display.hidden;
this.getField("AOff").display=display.hidden;
this.getField("Acc_Inv").display=display.hidden;
app.alert({cMsg: "Must be an accredited investor to invest in this Fund, please select yes.", nIcon:0});
}
If you take the yes portions and exclude the no, it seems to be working but with the No included, it does not work. The issue is, I want clients to be able to be able to switch from yes to no (in case they make a mistake) and have the correct fields displayed. At the moment you have to go back to the top and click individual, or joint, or corp, then yes to have the correct fields displayed. Another issue is that because the fields are the same, when the client clicks the first radio button selection, it opens the fields in the second portion which I do not want open until they say yes. I am wondering if I should change the name of the field but have it autofill with the previous data somehow.
Any help is much appreciated!
Thanks!
