Skip to main content
toddr14813053
Inspiring
September 13, 2020
Answered

Nested If Then with Multiple Conditions - Showing Last Option Chosen

  • September 13, 2020
  • 3 replies
  • 1506 views

Here's a stumper for you.

 

I have been trying to create a form which can have certain fields resize to handle additional input. There are 3 different fields that can be resized by the user and then the form spawns or deletes pages to show the fields at the sizes the people have chosen. In all, there are 27 different field combinations. In order to accomodate this, I have been trying to use nested if statements. The options are simply "Small Size", "Medium Size", and "Large Size" for each field. The problem I'm running into is that the beginning option when the form loads is "Small Size" and the page shows the appropriate size field. When I choose "Medium" though, "Small" stays. Then when I choose "Large",  "Medium" shows up. Then when I choose "Small" or "Medium", "Large" will show all with the proper accompanying pages. The form is showing the fields and pages of the last option that was chosen when you click the next option. Gosh this sounds insane and I hope it's not too confusing. I have other less complicated dropdowns to show or hide fields/pages and this is the only one that won't work. 

 

Here is the partial nested if-thens that I used.

 

var Drop1 = this.getField("Drop.01").value;

var Drop2 = this.getField("Drop.02").value;

var Drop3 = this.getField("Drop.03").value

 

if( event.value == "Drop.01" ) {

this.getField("1K.").display = display.visible; } \\ this seemed unnecessary before, so I took it out once. No Difference.

 

else if( Drop1 == "Small Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K1-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K1-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K1-4");

   expTplt3.spawn(numPages,false,false);

   this.pageNum = 1;}

   

   else if( Drop2 == "Medium Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K2-2");

   expTplt1.spawn(numPages,false,false); \\...

   

\\ ... additional options

}

 

else if( Drop1 == "Medium Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K4-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K4-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K4-4");

   expTplt3.spawn(numPages,false,false);

   this.pageNum = 1;}

 

\\ ... additional options

}

 

else if( Drop1 == "Large Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K7-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K7-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K7-4");

   expTplt3.spawn(numPages,false,false);

   var expTplt4 = getTemplate("1K7-5");

   expTplt4.spawn(numPages,false,false);

   this.pageNum = 1;}

 

\\ ... additional options

}

 

else { this.getField("1K.").display = display.visible; }

 

Hopefully you get the idea. There's probably a way easier way to do this, but I can't think of what it is at this point. I've been working on this for several days now. Help please!!! 

This topic has been closed for replies.
Correct answer toddr14813053

So I figured it out and I will place a sample below. My problem was that I made the incorrect assumption that I could only have each event.value option once in the code (so I could only use the options of small, medium and large once each). After I figured that was wrong, all I had to do was place the other conditions. Hope that makes sense. There is probably a more efficient way to do this, but I could get this one to work, so I'm happy.

 

if (event.value == "Drop.01") { 

this.getField("1K.").display = display.visible;

}

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Small Size")); {

var expTplt1 = getTemplate("1K1-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K1-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K1-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Medium Size")); {

var expTplt1 = getTemplate("1K10-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K10-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K10-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

// The rest of the conditions...

3 replies

toddr14813053
toddr14813053AuthorCorrect answer
Inspiring
September 16, 2020

So I figured it out and I will place a sample below. My problem was that I made the incorrect assumption that I could only have each event.value option once in the code (so I could only use the options of small, medium and large once each). After I figured that was wrong, all I had to do was place the other conditions. Hope that makes sense. There is probably a more efficient way to do this, but I could get this one to work, so I'm happy.

 

if (event.value == "Drop.01") { 

this.getField("1K.").display = display.visible;

}

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Small Size")); {

var expTplt1 = getTemplate("1K1-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K1-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K1-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Medium Size")); {

var expTplt1 = getTemplate("1K10-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K10-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K10-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

// The rest of the conditions...

Inspiring
September 13, 2020

It's not if( event.value == "Drop.01" ) { it should be Drop1 not Drop.01

toddr14813053
Inspiring
September 13, 2020

I'm sorry but that didn't make any difference to what I already had. The same exact thing happens.

Bernd Alheit
Community Expert
Community Expert
September 13, 2020

Where does you use the script?

toddr14813053
Inspiring
September 13, 2020

I'm not 100% sure what you mean, but i think you mean that you want to know which property field I am using... I hope.

 

As with my other javascript fields, I am using the "validate" dropdown property and NOT the "calculate" property.

 

Does that answer your question?

Bernd Alheit
Community Expert
Community Expert
September 13, 2020

At validation you will get the value of the dropdown with:

event.value