Hide checkbox based on value selected from another field

On my listing create or update form, I have a radio button called “radio1” with two options let 's say: “option1” and “option2”. Depending on the option selected in “radio1” I would like to show/hide checkBox1 or checkBox2.
That means:

  • if “option1” is selected, show “checkBox1” and hide “checkBox2”.
  • if “option2” is selected, show “checkBox2” and hide “checkBox1”.

Can you please help with the code snipped for this?

Thanks so much!

Hi,

If you mean to dynamically hide dependencies on selection, then there is no simple PHP snippet, it will require advanced customization. If you are familiar with coding or have a developer, we can provide general guidance.

Yes that’s what I meant. I am familiar with coding and can implement this if you give me general guidance. Thanks in advance!

Hi,

Here, you need to use not a PHP snippet but a JS script that will trigger on clicking on specific elements and, based on this, hide others, e.g. How to hide elements after button click in Javascript - Stack Overflow.

Thanks Andrii, I understand what to do but the problem is that the html fields don’t have an ids, so it is hard to target anything. For example see below what the html code looks like. I would like to hide one of the checkboxes depending on the value of the selected radio button. How do I target the correct div containing the checkboxes? Any help will be appreciated.

Never mind, I solved this using css selectors. Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.