Skip to content
Advertisement

Select Radio Button if a Dropdown is Selected

I’m wondering how I can use JavaScript to accomplish the following:

I have an input area with five dropdownlists, and each one has a corresponding radio button. When a dropdownlist is clicked to make a selection, I would like the radio button paired with it to become checked right then. Any help would be appreciated.

Advertisement

Answer

Its kind of simple really. Here is a small code for you. ID the 5 listboxes as “sel1”, “sel2” ,… ID the 5 radio buttons “rad1”, rad2,.. Make sure the radio buttons have same name though!

Next, put this function in as a javascrip:

function makeSelection(radioid){
document.getElementById(radioid).checked=true;
}

In the select boxes, attach onchanged listeners: ie;

<select ... onchange="makeSelection('rad1');" >.. for the 1st select box,
<select ... onchange="makeSelection('rad2');" >.. for the 2ns select box, etc.
Advertisement