Jump to content

change select button with radio button change


raman

Recommended Posts

I have an HTML page on which I have one select box with select options -1.5, -1.4, -1.3 ,...0, 0.1, 0.2......1.4, 1.5

0.0 is the default selected value.

 

I have a radio-button with 4 values, a b c d. a is the default selected radio button.

I beed a javascript  that would automatically change the value of select box to 0.1 if the user selects radio- button b, and change the value of select box to 0.2 if user selects button c, and change the value of select box to 1.0 if the user selects button d.

 

Does someone have an idea ?

add an onclick event to your radio buttons

 

create a function that will set the value of the selectbox

 

and call that function

 

with example code it would be

//function
setSelectValue(val){
  document.getElementById('SelectBox').value = val;
}

//radio buttons
<input type='radio' name='radiogroup' onclick='setSelectValue("0.0")' />a
<input type='radio' name='radiogroup' onclick='setSelectValue("0.1")' />b
<input type='radio' name='radiogroup' onclick='setSelectValue("0.2")' />c
<input type='radio' name='radiogroup' onclick='setSelectValue("1.0")' />d

//select box
<select id='SelectBox'>
  <option value='-1.5'>-1.5</option>
  ...
  <option value='0.0' selected>0.0</option>
  ...
</select>

 

when you click on one of the radio buttons, the selected value of the selectbox will change accordingly

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.