Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

How to refer to Radio button choice javascript + save it


Level 1



I am facing the following problem:


I have a radio button with values 1, 2. I have another fields X and Y that will need to be hidden/shown depending on the choice from the radio button.

So what I would like to do is:

1. when the form is initiated X and Y fields are not visible (if none of the values are checked yet - which is set by default). For this I used in the initiation field:

if (this.isNull = true) {fieldX.presence="hidden"; fieldY.presence="hidden"};


2. When I select radio button 1, the X field is visible only, when I select radio button 2, Y field is visible only

For this I used the change field and switch statement:

witch (this.rawValue) {
case "1":


case "2":


3. When I save the form and reopen it again, the form to remember the choice from before and depending on it it shows the right field. 

Here I have a problem, as when I re-open the form after saving, the button choice is saved (and appears to be clicked) but the fields are invisible and show only after clicking again on the buttons.

Does anyone know how to solve this?


I wanted to add in the initiation of the radio button something like:

if (this.rawValue == "1")


else (this.rawValue == "2")

{fieldY.presence ="visible"};


but it doesn't work, I can't seem to understand how to refer to these buttons and are these choices (1 or 2) rawValues or how do we call them?

I tried all the combination with =, ==, "1", 1 and nothing works. 

What am I doing wrong here?


thanks in advance for your help!




0 Replies