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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.