View Full Version : radio button problem, can anyone help?
dannygallo
10-16-2002, 01:12 AM
Hi, i'm trying to get a radio button to tick a checkbox somewhere else on the page when clicked. Does anyone know how to do this?
Thanks anyone
Danny
whammy
10-16-2002, 01:18 AM
<form>
<input type="radio" name="myradio" onclick="if(this.checked){this.form.mycheckboxname.checked=true}" />
<input type="checkbox" name="mycheckboxname" />
</form>
dannygallo
10-16-2002, 01:44 AM
What about if i want to have 3 radios and checks so that when a radio button is selected, only it's associated checkbox is checked and unchecks any already checked?
Does that make any sense? I know it's starting to sound like a riddle
Thanks anyone
Danny
whammy
10-16-2002, 01:53 AM
That's easy... do you have an example? It also helps if you post the code you're having problems with and explain in plain English what the problem is, in detail.
It's hard to resolve problems without seeing what kind of problem(s) you're running into. :D
dannygallo
10-16-2002, 02:10 AM
Hi Whammy, I have a page where i have 2 radio buttons and 2 checkboxes further down the page.
When radio button1 is selected; checkbox1 becomes checked.
When radio button2 is selected; checkbox2 becomes checked and checkbox1 becomes unchecked. And vice e versa
So the checkboxes work in accordance with the radio buttons.
Does that make anymore sense?
Danny
whammy
10-16-2002, 02:15 AM
That makes perfect sense. How 'bout you post the relevant code (just the checkboxes and radio buttons) and the form "name" you are using?
It should then be simple to write a function that does what you want. :D
dannygallo
10-16-2002, 02:23 AM
Here is the basic skeleton of the code.
<form name="form1" method="post" action="">
<p>
<input type="radio" name="radiobutton" value="radiobutton">
selection 1 </p>
<p>
<input type="radio" name="radiobutton" value="radiobutton">
selection 2</p>
<p>
<input type="checkbox" name="checkbox" value="checkbox">
selection 1</p>
<p>
<input type="checkbox" name="checkbox2" value="checkbox">
selection 2</p>
</form>
Is this any help?
Thanks again
Danny
glenngv
10-16-2002, 03:01 AM
<form name="form1" method="post" action="">
<p>
<input type="radio" name="radiobutton" value="radiobutton" onclick="toggle(this.form.checkbox,this.form.checkbox2)"> selection 1 </p>
<p>
<input type="radio" name="radiobutton" value="radiobutton" onclick="toggle(this.form.checkbox2,this.form.checkbox)"> selection 2</p>
<p>
<input type="checkbox" name="checkbox" value="checkbox"> selection 1</p>
<p>
<input type="checkbox" name="checkbox2" value="checkbox"> selection 2</p>
</form>
<script>
function toggle(objCheck,objUncheck){
objCheck.checked=true;
objUncheck.checked=false;
}
</script>
but why would you have to do this if you only have 2 checkboxes that act like radio buttons?
why not just put 2 radio buttons instead?
adios
10-16-2002, 03:05 AM
Had the same question...nice riddle, though.
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function checkoff(oRadio) {
var radiogroup = oRadio.form.radiobutton;
for (var i=0; i<radiogroup.length; ++i)
oRadio.form['checkbox' + (i+1)].checked = radiogroup[i].checked;
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<p>
<input type="radio" name="radiobutton" value="radiobutton"
onclick="checkoff(this)">
selection 1 </p>
<p>
<input type="radio" name="radiobutton" value="radiobutton"
onclick="checkoff(this)">
selection 2</p>
<p>
<input type="checkbox" name="checkbox1" value="checkbox" onclick="return false;">
selection 1</p>
<p>
<input type="checkbox" name="checkbox2" value="checkbox" onclick="return false;">
selection 2</p>
</form>
</body>
</html>
dannygallo
10-16-2002, 01:59 PM
Cheers Guys!!!!!!!!!!!!!!!!!!
You sorted me out, thanks for all your help
I owe ya beers next time your in london.
:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.