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

if choose something in drop down then checkbox is checked

Avatar

Level 2

I want to pick from a list in the drop down.  Depending on what is choosen then a box will be checked automatically.  This

is what I have so far for script.

if (dropdown == "blah") then this.rawValue = 1

I am not sure if it should be JavaScript or FormCalc...I assume JavaScript since there is no calculation.  I am also unsure whether to put the script on the dropdown box or the checkbox.  Also which event do i use?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The == is used to compare two values ...so you are using it correctly in the if statement. When yo want to assign a value to an object then a single = sign is used. So your code shoudl be CheckTwo.rawValue = 1.

You can use an OR condition to check multiple values in th eif statement. So if the checkbox is to be checked if they choose blah, blah1 or blah2 then you coudl do this:

 

if ((this.rawValue == "blah") || (this.rawValue == "blah1") || (this.rawValue == "blah2")) {

     CheckTwo.rawValue = 1;

} else {

     CheckTwo.rawValue = 0;

}

You have to make sure to uncheck the checkbox if none of those options are chosen. That way if they choose  one of those options (the checkbox gets turned on) then they change their minds and choose a different value it must be turned off.

Make sense?

paul

View solution in original post

7 Replies

Avatar

Level 10

You need to place the code in the Exit/ Change event of the Dropdown.

Choose JavaScript.

Modified script.

if (dropdown.rawValue == "blah")

     this.rawValue = 1;

Thanks

Srini

Avatar

Level 2

I have at least twenty items to choose from in the drop down box.  So i need to script for ea

ch possible choice.  How do i do that in java script?

if (this.rawValue == "blah)

  CheckTwo.rawValue = 1;

elseif (this.rawValue == "blah2")

  CheckTwo.rawValue = 1:

There are probably 10 that check one box and another then that check a different box.

Thanks

Avatar

Level 10

You can either use multiple if elseif conditions (OR) you can use the switch case statements.

switch(n)
{
case 1:
  execute code block 1
  break;
case 2:
  execute code block 2
  break;
default:
  code to be executed if n is different from case 1 and 2
}

One correction in my previous post, you can not access rawValue in Change event so you need to place the above code only in Exit event.

Thanks

Srini

Avatar

Level 2

I am still having trouble with this.  I want to choose a word from the drop down box (that has at least 25 options) and depending on the word I choose i want 1 or 2 checkboxes checked.

This is the script i have so far.  Right now i have it set up on the drop down box as and exit.

 

if (this.rawValue == "blah")

CheckTwo.rawValue == 1;

if (this.rawValue == "blah2")

CheckEight.rawValue == 2;

There are 15 items that would make one check box checked and then 10 for the other checkbox.  It would be nice if I could just list them all out.

Please HELP

Avatar

Correct answer by
Former Community Member

The == is used to compare two values ...so you are using it correctly in the if statement. When yo want to assign a value to an object then a single = sign is used. So your code shoudl be CheckTwo.rawValue = 1.

You can use an OR condition to check multiple values in th eif statement. So if the checkbox is to be checked if they choose blah, blah1 or blah2 then you coudl do this:

 

if ((this.rawValue == "blah") || (this.rawValue == "blah1") || (this.rawValue == "blah2")) {

     CheckTwo.rawValue = 1;

} else {

     CheckTwo.rawValue = 0;

}

You have to make sure to uncheck the checkbox if none of those options are chosen. That way if they choose  one of those options (the checkbox gets turned on) then they change their minds and choose a different value it must be turned off.

Make sense?

paul

Avatar

Level 2

Thank You...that has helped.

How do you make those two parallel lines.  I can not figure that out.  I just copy pasted from your email.

Avatar

Level 1

The two 'parallel lines' Paul used are two 'pipe' characters (ASCII code 124). Usually it can be found in the keyboard, have a look at the key for backslash "\". 

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] ----