Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

How to refer to Radio button choice javascript + save it

ana-marija
Level 1
Level 1

Hello,

 

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":
fieldX.presence="visible";

fieldY.presence="hidden";
break;

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

fieldX.presence="hidden";
break;
}

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")

{fieldX.presence="visible"};

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