Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
There are errors in your code. Check the JS Console and fix them before doing anything else...
Copy link to clipboard
Copied
I unfortunately, I do not know what that is and often when I check the code using programs online I do not know how to fix it (even with error statements) because as I stated I am very new to Java.
Copy link to clipboard
Copied
First off, it's JavaScript, not Java. The two sound similar, but are not the same at all.
OK, the error is in this line:
else {(v=="No");
It simply doesn't make sense.
It can be either:
else if (v=="No") {
Or it can be:
else {
Copy link to clipboard
Copied
You have a lot of duplicate coding to hide fields. I would set the default display for all those fields that could be hidden to hidden before the test to set the display of certain fields.
One can also use the "switch" statement for the selection of the fields to display.
// hide I, J, & C.Corp.Type fields;
this.getField("I").display=display.hidden;
this.getField("J").display=display.hidden;
this.getField("C.CorpType").display=display.hidden;
// display fields based on investor type
switch (hthis.getField("InvestorType").value;v)
{
case "Individual:
this.getField("I").display=display.visible;
break;
case "Joint":
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
break;
case "Corp":
this.getField("C.CorpType").display=display.visible;
break;
default:
// no valid invetor type;
app.alert("Must select an investor type", 1, 0);
break;
}
var v = this.getField("Accr_InvYN").value;
var x = this.getField("InvestorType").value;
var y = this.getField("CorpType").value;
// set initial state;
this.getField("I.Province").display = display.hidden;
this.getField("I.FName").display = display.hidden;
this.getField("I.Surname").display = display.hidden;
this.getField("I.Sign").display = display.hidden;
this.getField("S").display = display.hidden;
this.getField("J").display = display.hidden;
this.getField("C").display = display.hidden;
this.getField("AOff").display = display.hidden;
this.getField("Acc_Inv").display = display.hidden;
switch(true) {
case (v == "No" || v == "Off"):
app.alert({cMsg: "Must be an accredited investor to invest in this Fund, please select yes.", nIcon:0});
break;
case (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("Acc_Inv").display=display.visible;
break;
case (v == "Yes" && x == "Joint") :
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
this.getField("S").display=display.visible;
this.getField("Acc_Inv").display=display.visible;
break;
case (v == "Yes" && x == "Corp"){:
this.getField("S").display=display.visible;
this.getField("Acc_Inv").display=display.visible;
break;
default:
app.alert("Must select whether an accredited investor or not", 1, 0);
break;
}
Have you set the default for any of your check boxes or radio buttons?
How to you deal with the situation where nor check box in an exclusionary group has not been selected?
Copy link to clipboard
Copied
This is great! I am mostly using radio buttons because the client can only be one of the choices in my scenarios.
I have not set a default for any of my radio buttons because I find that if not clicked then the code is not executed. I am assuming this is because of two issues, one the trigger is mouse up, not sure if changing this to on blur or something similar would fix this and secondly because there are issues with how I coded it
. This defiantly is a global issue I want to fix but it was a too advanced for me to figure out on my own.
The only default states I have is whether the field is required or not. All the radio buttons are required and must be selected, so I haven't thought too much about what happens when nothing is selected. Any thoughts on this would be lovely!
Thank you!
Copy link to clipboard
Copied
Unless one radio button is not selected the value is "Off" and has a value, so some test for if a required field is completed or not do not work, especially the a test comparing to a null string.
Also when one tries to access the field that has the focus, one does use the "getField" method to get the value of that field. It is better to use "event.target.value". The value of the field is not set until one exits the field. The value for the "getField" method is the value of the field upon entry into the field.
Copy link to clipboard
Copied
Unfortunately, I cannot get this to work. I keep having SyntaxError: missing ) after switch expression 6: at line 7 but cannot for the life of me seem to locate it.
Copy link to clipboard
Copied
Post the full code.
Copy link to clipboard
Copied
Please see comment 4 or below for full code.
// hide I, J, & C.Corp.Type fields;
this.getField("I").display=display.hidden;
this.getField("J").display=display.hidden;
this.getField("C.CorpType").display=display.hidden;
// display fields based on investor type
switch (hthis.getField("InvestorType").value;v)
{
case "Individual:
this.getField("I").display=display.visible;
break;
case "Joint":
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
break;
case "Corp":
this.getField("C.CorpType").display=display.visible;
break;
default:
// no valid invetor type;
app.alert("Must select an investor type", 1, 0);
break;
}
var v = this.getField("Accr_InvYN").value;
var x = this.getField("InvestorType").value;
var y = this.getField("CorpType").value;
// set initial state;
this.getField("I.Province").display = display.hidden;
this.getField("I.FName").display = display.hidden;
this.getField("I.Surname").display = display.hidden;
this.getField("I.Sign").display = display.hidden;
this.getField("S").display = display.hidden;
this.getField("J").display = display.hidden;
this.getField("C").display = display.hidden;
this.getField("AOff").display = display.hidden;
this.getField("Acc_Inv").display = display.hidden;
switch(true) {
case (v == "No" || v == "Off"):
app.alert({cMsg: "Must be an accredited investor to invest in this Fund, please select yes.", nIcon:0});
break;
case (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("Acc_Inv").display=display.visible;
break;
case (v == "Yes" && x == "Joint") :
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
this.getField("S").display=display.visible;
this.getField("Acc_Inv").display=display.visible;
break;
case (v == "Yes" && x == "Corp"){:
this.getField("S").display=display.visible;
this.getField("Acc_Inv").display=display.visible;
break;
default:
app.alert("Must select whether an accredited investor or not", 1, 0);
break;
}
Copy link to clipboard
Copied
This line is completely wrong:
switch (hthis.getField("InvestorType").value;v)
And so is this one:
case "Individual:
Copy link to clipboard
Copied
I have fixed those errors but am still getting a syntax error: missing ) after switch expression 6: at line 7.
switch (this.getField("InvestorType").value;v)
{
case "Individual:
this.getField("I").display=display.visible;
break;
case "Joint":
this.getField("I").display=display.visible;
this.getField("J").display=display.visible;
break;
case "Corp":
this.getField("C.CorpType").display=display.visible;
break;
default:
// no valid invetor type;
app.alert("Must select an investor type", 1, 0);
break;
}
No matter what I do I cannot get it to work.
Copy link to clipboard
Copied
With a form with such a complex decision, it would be best to supply a sample with the issue or are we expected to recreate a form.
Have you checked to see if you have other scripts that are changing these fields?
Copy link to clipboard
Copied
Honestly, I am not sure how I could be more clear. No, I am not expecting anyone to recreate the form, to be honest, it is much more complex then this one piece. I ask specifically why I was getting a syntax error in that one specific spot on line 7. If you do not want to help, then feel free to not. This line:
switch (this.getField("InvestorType").value;v)
{
saying I am missing a ) after the expression.
Copy link to clipboard
Copied
I was able to figure out why I was receiving the error. No need to reply.
Copy link to clipboard
Copied
Remove the ";v" part from that code.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more