You are viewing limited content. For full access, please sign in.

Question

Question

select radio button based on drop down selection

asked on March 23, 2022

HELP, please!?

 

Would like a radio button to be selected based on the same value as a drop down field using javascript.

Can't seem to get it to work. Could someone please take a look and tell me what am i missing? Much appreciated!

$(document).ready(function () {
   $("#q140").on("change", function() {
    var value = $(this).val();
    $('.myradio').find($('input[value="' + value + '"]')).attr('checked', true);
  });
});

0 0

Answer

SELECTED ANSWER
replied on March 23, 2022

Hi Jo,

You are pretty closed to the solution, except that val() needs to be called on the select element of the dropdown field to get the selected option according to https://doc.laserfiche.com/laserfiche.documentation/11/administration/en-us/Default.htm#../Subsystems/Forms/Content/Javascript-and-CSS/Javascript%20Selectors.htm

And in my test, reset radio button before new select is necessary.

So try following JS code:

$(document).ready(function () {
   $("#q140").on("change", function() {
    var value = $("#q140 select").val();
    $('.myradio input').attr('checked', false);
    $('.myradio').find($('input[value="' + value + '"]')).attr('checked', true);
  });
});
2 0
replied on March 24, 2022

Thank you, Ziyan, for clarifying the select element! I tested the code and it did not work for me. but when I took out line 4 it worked.

$(document).ready(function () {
   $("#q3").on("change", function() {
    var value = $("#q3 select").val();
   $('.myradio').find($('input[value="' + value + '"]')).attr('checked', true);
  });
});

 

Much appreciated!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.