Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

If statement question in Adobe Designer

Avatar

Former Community Member
This code here:



else if(application.page1.citizen.rawValue==0){

app.alert("Please select whether you are a United States citizen");

xfa.host.setFocus("application.page1.citizen");

}

else if(application.page1.citizen.rawValue==2){

app.alert("Please select whether you are legally permitted to be employed in the United States");

xfa.host.setFocus("application.page1.legally");

}



The first if statement checks to see if the group of radio button(s) "citizen" has been selected (yes or no). Works fine. If the citizen radio button with a value of 2 (no) has been selected, kick out another error message indicating additional radio buttons (legally) is needing selection. This is my problem, when I select yes or no on the "legally" group of radio buttons, the second alert keeps popping up. Why can't it kick out and go on through the page? Am I missing something logically in the JS?



Any help or suggestions would be appreciated.
8 Replies

Avatar

Former Community Member
What event of what object did you put your script in?



Chris

Adobe Enteprise Developer Support

Avatar

Former Community Member
So the user clicks the print button after selecting no for teh citizen radio button, it gives an error message telling them to select a value for legally. They do this then click the print button again, and again get told to select something in legally?



Hopefully I've understood... and if so, it's because your if statement checks to see the value for citizen and then tells them to fill somethign in for legally without first checking to see if they had already filled in for legally. Adding the extra logic should fix it.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Well, I've been thinking that and I can't nail what I could be missing logically. I've got:



else if(application.page1.citizen.rawValue==0){

app.alert("Please select whether you are a United States citizen");

xfa.host.setFocus("application.page1.citizen");

}

else if(application.page1.citizen.rawValue==2){

else if(application.page1.legally.rawValue==1 || application.page1.legally.rawValue==2){

app.alert("Please select whether you are legally permitted to be employed in the United States");

xfa.host.setFocus("application.page1.legally");

}

}



The second if statement checks to see if they selected "no" for citizen. I've added in another if statement checking to see if legally radio buttons have already been filled in. Using the above approach kills my script from executing period.

Avatar

Former Community Member
Well, off the top of my head you should remove the else from:



else if(application.page1.legally.rawValue==1 || application.page1.legally.rawValue==2){



It's an entirely new if statement.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Yeah, I'm stumped at the moment as to what it doesn't like. I have this and it still kills my script:



else if(application.page1.citizen.rawValue==0){

app.alert("Please select whether you are a United States citizen");

xfa.host.setFocus("application.page1.citizen");

}

if(application.page1.citizen.rawValue==2){

else if(application.page1.legally.rawValue==0){

app.alert("Please select whether you are legally permitted to be employed in the United States");

xfa.host.setFocus("application.page1.legally");

}

}



See if I can get a JavaScript person to see if they can spot something.

Avatar

Former Community Member
The problem is you have:



if (...) {

else if (..) {

...

}

}



when you should have:



if (...) {

if (..) {

...

}

}



Btw, if you don't have Acrobat set up to automatically show the console when an exception happens you can hit CTRL-J to show the console and see what the exception is.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Yeah, I came to this about 10 minutes ago myself:



else if(application.page1.citizen.rawValue==0){

app.alert("Please select whether you are a United States citizen");

xfa.host.setFocus("application.page1.citizen");

}

if(application.page1.citizen.rawValue==2){

if(application.page1.legally.rawValue==0){

app.alert("Please select whether you are legally permitted to be employed in the United States");

xfa.host.setFocus("application.page1.legally");

}



No works now, not the yes once its been filled in. I pressed Cntrl + J and don't see anything.