Setting a radiobutton to be required or NOT required based on the users action.

Hi,

I’m creating a form from scratch using radiobuttons, where the user answers some questions. Based on what the user answers, other relevant questions are expanded on the site.

For now all the radiobuttons are set to NOT required, as the user only needs to see the questions relevant to his/her’s previous answer.

I am trying to write some code that changes the “required field” to be true/false, if an other radio button is checked.

I’ve created an example in the image below:

If the user answers YES whether he/she has a favourite colour, I want the input below to be a required field.

If he/she answers NO, I want to make the question below to NOT be required.

I’m new to coding. Any help is highly appreciated!

Thank you.
Marte

Thanks J.D, that was helpfull!

It seems to be working, but both buttons go red, as if the user tried to send the form without checking one of the options. I read in a different thread that this is a bug in wix, is that still the case? Thank you.

I haven’t tested it.
Anyway I think in your specific case you should hide/collapse the 2nd radioButtonGroup if the first one is not selected.

Yes I’ve implemented that. Thanks for helping out!

You’re welcome