Expand my Community achievements bar.

SOLVED

Trouble with nested if/else statements in dropdown options

Avatar

Level 3

Hi,

I'm having trouble trying to add conditions together.

I have a form that has so many dropdowns with the same 1-5 options. However, a user must not choose the same option in any two or more different drop downs. e.g. if dropdown 1 has an option of "1" then dropdown 2 must have a different option, dropdown 3 must have a different option etc.

I cant seem to get my script running properly. I need to combine statements.

Can someone be of any help please?

My script for the first dropdown is:

if (this.rawValue = Drop2.rawValue)
{

xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");


}else if (this.rawValue = Drop3.rawValue){

xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
}else if (this.rawValue = Drop4.rawValue){

xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");
}else if (this.rawValue = Drop5.rawValue){

xfa.host.messageBox("You cannot have duplicate positions for different financial threats/risks/hazards. Please choose another position!");

}

else if (this.rawValue == 1 && this.rawValue != Drop2.rawValue && this.rawValue != Drop3.rawValue && this.rawValue != Drop4.rawValue && this.rawValue != Drop5.rawValue){
FINANCIAL_1_1.rawValue = FINANCIAL_1.rawValue;
} else if (this.rawValue == 2){
FINANCIAL_1_2.rawValue = FINANCIAL_1.rawValue;
} else if (this.rawValue == 3){
FINANCIAL_1_3.rawValue = FINANCIAL_1.rawValue;
}

it just doesnt seem to work.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Send the form to stwalker.adobe@gmail.com and I can take a look.

Steve

View solution in original post

4 Replies

Avatar

Former Community Member

How about this....

I have five drop-down lists ('dd1' thru 'dd5'). The exit event on each drop-down is the same, as depicted by the exit event on 'dd1' below.

// form1.page1.subform1.dd1::exit - (JavaScript, client)

if (!(this.isNull)) {

  myScriptObject.validateDropDowns();

}

The exit event calls validateDropDowns() on the script object 'myScriptObject'. The functions is as follows:

// form1.#variables[0].myScriptObject - (JavaScript, client)

function validateDropDowns() {

  var dd1 = form1.page1.subform1.dd1.rawValue;

  var dd2 = form1.page1.subform1.dd2.rawValue;

  var dd3 = form1.page1.subform1.dd3.rawValue;

  var dd4 = form1.page1.subform1.dd4.rawValue;

  var dd5 = form1.page1.subform1.dd5.rawValue;

  var ddArray = new Array(dd1,dd2,dd3,dd4,dd5);

  ddArray.sort();

  var last = "";

  for (var i=0; i < ddArray.length; i++) {

    if (i == 0) {

      last = ddArray[i];

    }

    else {

      if (ddArray[i] != null) {

        if (ddArray[i] == last) {

          xfa.host.messageBox("This option was previously selected.");

          i = ddArray.length;

        }

        else {

          last = ddArray[i];

        }

      }

    }

  }

}

The function captures each drop-down value and loads the array 'ddArray' which is then sorted. I iterate over the sorted array and determine if the same drop-down value (except 'null') exists in the array.
Steve

Avatar

Level 3

thanks Steve,

It works. This means the first part of my dropdown function is sorted.

However, for the second part, I'd like to have a text box where the rawValue of the dropdown option reflects.

e.g.

after an option in dd1 is picked, the rawValue for dd1 is transfered to a readonly textbox.

I've tried adding the following script after the validation script in the exit event of the dd1 but its not working.

if(this.rawValue == 1){
this.rawValue = FINANCIAL_1_1.rawValue;
} else if (this.rawValue == 2){
this.rawValue = FINANCIAL_1_2.rawValue;
} else if (this.rawValue == 3){
this.rawValue = FINANCIAL_1_3.rawValue;
}

I would have loved to attach my form to this thread but I do not have an option for that.

Also, after validating with 'myScriptObject' can we add a script to return the dropdown value to the default 'null'?

Thanks again for your reply.

Avatar

Correct answer by
Former Community Member

Send the form to stwalker.adobe@gmail.com and I can take a look.

Steve

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----