These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

nested if statements not working

PetafromOz
Registered: Jun 8 2009
Posts: 230

When selections are made from a listbox (TACList), the listbox is hidden and another field (TACResults) displayed with the listbox values loaded into them. However if no selections are made, I want the user to be asked if that's what they really want.

1. If so, then, the listbox stays open, the results box stays hidden and the focus is set to a freeform description field.
2. If not, I want the focus back on the listbox so they can make selection(s).

I have been successful in doing all of this, but not all at once. If I apply only the second part of the script (ie. when selections are made), that part works perfectly.

If I apply the first part of the script independently, it works too.

But when I try to lump the tasks together, it fails.

I have the following script:

----- form1.TACPg1.TACSF.IndSF.TACList::exit: - (JavaScript, client) -------------------------------

if(this.rawValue == 0) //if no selection made
{
var noSelect = xfa.host.messageBox("Are you sure you don't want to make any selections?","No selections",2,2); //are you sure? - yes or no
if(noSelect == 4); //if yes
xfa.host.setFocus(IndSF.TACDtls); //set focus to the details field (& don't display the results box)
}
else
{
if(noSelect) == 3); //if no
xfa.host.setFocus(IndSF.FakeDDnFldSF.BlankBtn); //set the focus to the button
}
else
{
if(this.rawValue > 0); //otherwise if something is selected,
{
TACResults.presence = "visible"; //show the results
TACResults.rawValue = this.rawValue; //load the results of the list
TACDtls.presence = "visible"; //show the details field
xfa.host.setFocus(TACDtls); //set the focus to the details field
this.presence = "hidden"; //hide the dropdown list
xfa.host.resetData("xfa.form.form1.TACPg1.TACSF.IndSF.TACList"); //reset the dropdown list
}

I obviously have some syntax or structure wrong. Can anyone assist please?

from way... underground at Parkes - central West NSW - Australia

My Product Information:
LiveCycle Designer, Windows
suewhitehead
Registered: Jun 3 2008
Posts: 232
I found this example of a nested if statement.
if (condition a) {
do action 1
} else {
if (condition b) {
do action 2
} else {
... etc.
}
}Maybe this will help. I always find it confusing as to where to put the brackets and getting the right number of closing brackets. I think this may be your problem also. But I am rather new to Javascript myself so I could be wrong.
So based on the example, you might try it this way:

if(this.rawValue == 0) //if no selection made
{
var noSelect = xfa.host.messageBox("Are you sure you don't want to make any selections?","No selections",2,2); //are you sure? - yes or no
if(noSelect == 4); //if yes
{xfa.host.setFocus(IndSF.TACDtls); //set focus to the details field (& don't display the results box)
}
if(noSelect) == 3); //if no
{xfa.host.setFocus(IndSF.FakeDDnFldSF.BlankBtn); //set the focus to the button
}
}
else
{
TACResults.presence = "visible"; //show the results
TACResults.rawValue = this.rawValue; //load the results of the list
TACDtls.presence = "visible"; //show the details field
xfa.host.setFocus(TACDtls); //set the focus to the details field
this.presence = "hidden"; //hide the dropdown list
xfa.host.resetData("xfa.form.form1.TACPg1.TACSF.IndSF.TACList"); //reset the dropdown list
}
PetafromOz
Registered: Jun 8 2009
Posts: 230
Hi Sue,

Yes I believe you're right. After I submitted this question I worked with this extensively. Even wrote it out and drew boxes around each group and sub-group of if statements to make sure I had the brackets right - and I STILL couldn't make it work. Drove me insane. It's one of those things that if you do it too often, you can't see the wood for the trees.

So I'll give your version a go and let you know if it worked.
Thanks, Peta

from way... underground at Parkes - central West NSW - Australia

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you tried to simplify the coding by testing a value only once for one of 2 mutually exclusive results or only the expected result and all other repsones are treated as a no response?
// test for selectionif(this.rawValue <> 0) {// something has been selected, TACResults.presence = "visible"; //show the resultsTACResults.rawValue = this.rawValue; //load the results of the listTACDtls.presence = "visible"; //show the details fieldxfa.host.setFocus(TACDtls); //set the focus to the details fieldthis.presence = "hidden"; //hide the dropdown listxfa.host.resetData("xfa.form.form1.TACPg1.TACSF.IndSF.TACList"); //reset the dropdown list} else {// no selection has been madevar noSelect = xfa.host.messageBox("Are you sure you don't want to make any selections?","No selections",2,2); //are you sure? - yes or no// yes selectionif(noSelect == 4); { //if yesxfa.host.setFocus(IndSF.TACDtls); //set focus to the details field (& don't display the results box)} else {// all other response xfa.host.setFocus(IndSF.FakeDDnFldSF.BlankBtn); //set the focus to the button} // end response yes/no } // end event value processing

George Kaiser

PetafromOz
Registered: Jun 8 2009
Posts: 230
Thankyou both so much for your efforts, but I'm afraid I still can't make it work even trying both your suggestions. To achieve a deliverable, I've tackled it in a different way by placing scripts in receiving fields to handle each scenario. But I hate not solving problems and will still try later to get this nested if situation to work.

Thanks again, Peta

from way... underground at Parkes - central West NSW - Australia