Forums

radio box change based on menu selection

scottchr 23 Mar, 2016
I have a drop down menu and checkbox group. For example, like this:

Menu
Option 1
Option2

Radio button
yes
no - turned on by default

is it possible, through the use of an element event, to make it so that if menu option 1 is selected that the Yes option would be selected for the radio button?
GreyHead 24 Mar, 2016
Hi scottchr,

Yes and no, you could do it but you'd need to use a Custom function - and, in this case you might just as well use custom JavaScript without using the event.
jQuery(document).ready(function(jQ) {
  // run the checkon page load and when the select changes
  setRadio();
  jQ('#dropdown1').on('click', setRadio);

  function setRadio() {
    if ( jQ('#dropdown1 option:selected').val() == 'option_1' ) {
      jQ('input:radio[name=radio2]').val(['yes']);
    } else {
      jQ('input:radio[name=radio2]').val(['no']);
    }
  }
});
You need to update the element names, ids and values to match yours.

You can see my test here

Bob
scottchr 24 Mar, 2016
Thanks for the info. I was hoping there might be a simple way to do it through an event in the drop down menu field but your script will make it easy for me to apply using a function instead.

Thanks again for your help.
This topic is locked and no more replies can be posted.