Disable radio buttons?

J

James Gardner

Within a single form I have a dropdown select box with 2 options and 2
radio buttons. If someone selects option 2 in the dropdown I would like to
make the radio buttons disabled, such that you cannot select either one of
them. If someone selects option 1 in the dropdown I would like the radio
buttons to be re-enabled. Is this, or something similar (checkboxes
instead of radio, etc) possible, and if so can someone point me to an
example? Thanks
 
S

Stephen Chalmers

James Gardner said:
Within a single form I have a dropdown select box with 2 options and 2
radio buttons. If someone selects option 2 in the dropdown I would like to
make the radio buttons disabled, such that you cannot select either one of
them. If someone selects option 1 in the dropdown I would like the radio
buttons to be re-enabled.

You need a simple function to toggle all the buttons in a specifed set:

<SCRIPT type='text/javascript'>

function enableRB(bSet, flag)
{
for(var i=0; i<bSet.length; i++)
bSet.disabled=!flag;
}

</SCRIPT>

Then assuming that your set of radio buttons is *named* 'rbSet' ,

<SELECT onchange='enableRB( this.form.rbSet, this.selectedIndex==1?false:true )'>
 
R

RobG

Stephen said:
You need a simple function to toggle all the buttons in a specifed set:

<SCRIPT type='text/javascript'>

The example can be simplified a little if both the following changes are
made:
function enableRB(bSet, flag)
{
for(var i=0; i<bSet.length; i++)
bSet.disabled=!flag;


bSet.disabled = flag;
}

</SCRIPT>

Then assuming that your set of radio buttons is *named* 'rbSet' ,

<SELECT onchange='enableRB( this.form.rbSet, this.selectedIndex==1?false:true )'>

<SELECT onchange='enbleRB( this.form.rbSet, (this.selectedIndex==1) )'>

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top