Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

can you controll multiple (6) subforms show/hide from droplist

Avatar

Level 4

Hi I’m trying to get a drop down list to control 6 subform options

List values are

1 = none value =1

2= 1 value = 2

3= 2 value = 3

4=3 value = 4

5=4 value = 5

6= 5 value = 6

five sub-forms

codno1, codno2, codno3, codno4 (each a numerical/date field)

and codno5 (an advisory to overhaul)

I want to fix javascript to the exit/change ?? event of the droplist

something like this…..

but I’m no programmer and am unsure how to structure correctly – any help/pointers please!

I can get it to do the first one  with {

if (this.rawValue == "2")

cod1date.presence = "visible"

}

{

if (this.rawValue =="3")

cod1date.presence = "visible" && cod2date = "visible";

but when I try to control multiple subforms it breaks ……

I thought something like below made sense……

if this.rawValue == 6

codno1.presence && codno2.presence && cono3.presene && codno4.presence && codno5.presence = “visible”;

else if

this.rawValue == 5 

codno1.presence && codno2.presence && cono3.presene && codno4.presence && = “visible” && condno5.presence = “hidden”;

else if

this.rawValue == 5 

codno1.presence && codno2.presence && cono3.presene = “visible” && codno4.presence && condno5.presence = “hidden”;

else if ……………………. And so on…………….

1 Accepted Solution

Avatar

Correct answer by
Level 10

The syntax for your switch() function isn't correct. You missed out quotes around the test value and the break statements.

var A = this.rawValue ;

switch(A)
{
case "5":

break;

case "6":
    cod4date.presence = "visible";

break;

case "4":
    cod3date.presence = "visible";

break;

case "3":
    cod2date.presence = "visible";

break;

case "2":
    cod1date.presence = "visible";

break;

/*

You can also have default settings too:

*/

//default:

}

View solution in original post

5 Replies

Avatar

Former Community Member

I woudl use a javascript switch statement instead of trying to nest a series of if statements (it will get very confusing). Do a google search for Javascript switch statement on the web and it will give you the appropriate syntax. Then you can test the value of your dropdown and cause the execution of your code block for the appropriate case.

Paul

Avatar

Level 4

hi paul i have put this code toghether and put it on the exit even but i get nothing but i get nothing when i click any of the drop option lists (i have the four codno fields "hidden" by this.presence "hidden" on thier initilize function )

var A = this.rawValue ;

switch(A)
{
case 5:
case 6:
    cod4date.presence = "visible";

case 4:
    cod3date.presence = "visible";

case 3:
    cod2date.presence = "visible";

case 2:
    cod1date.presence = "visible";
}

any pointers as to what im doing wrong here .........

cheers

Avatar

Former Community Member

Can you post your form and I will have a look when I get a chance.

Paul

Avatar

Correct answer by
Level 10

The syntax for your switch() function isn't correct. You missed out quotes around the test value and the break statements.

var A = this.rawValue ;

switch(A)
{
case "5":

break;

case "6":
    cod4date.presence = "visible";

break;

case "4":
    cod3date.presence = "visible";

break;

case "3":
    cod2date.presence = "visible";

break;

case "2":
    cod1date.presence = "visible";

break;

/*

You can also have default settings too:

*/

//default:

}

Avatar

Level 4

thank you everyone for the help - was fairly new AND lost.... that worked.

cant believe something as simple as "" took a few days but hey thanks its working....

sorry for the delay in response in the middle of it all i had a HDD go weird and had to resore from backups.... a real pain but hey all on the up side now.... somebodys way of telling the boss we need a new computer i think .... although the odds of that i7 i've been lusting after seem slim still..

cheers, its great to see users helping one another along .... it makes a lot of difference to the lost newbies like us