View Full Version : checkbox checked check another checkbox
yes I know seems a joke of words but i need exactly this:
2 checkbox where the second one follow the action of the first one.
thanks in advance
beetle
01-08-2003, 07:19 PM
<form>
<input type="checkbox" name="checkers" id="checker1" onclick="this.form.checker2.checked = this.checked;" />
<input type="checkbox" name="checkers" id="checker2" />
</form>
arnyinc
01-08-2003, 07:24 PM
Does the first one follow the action of the second as well? If so, add a set_c1() function that is just the opposite.
<html>
<head>
<script language="javascript">
function set_c2(x){
if (x.checked)
document.myform.c2.checked=true;
else
document.myform.c2.checked=false;
}
</script>
</head>
<body>
<form name="myform">
<input type="checkbox" name="c1" value="on" onclick="set_c2(this)"><input type="checkbox" name="c2" value="on">
</form>
</body>
</html>
yes that's work fine but i need something like this and so I need that you can choose only one of otpion (male-female).
please take a look at code
<script language="javascript">
function set_c2(x){
if (x.checked)
document.myform.c2.checked=true;
else
document.myform.c2.checked=false;
}
function set_c3(x){
if (x.checked)
document.myform.c3.checked=true;
else
document.myform.c3.checked=false;
}
</script>
</head>
<body>
<form name="myform">
<p> male
<input type="radio" name="male" value="male" onclick="set_c2(this)">
female
<input type="radio" name="female" value="female" onClick="set_c3(this)">
</p>
<p>
<input type="checkbox" name="c2" value="on">
maleicon
<input type="checkbox" name="c3" value="on" onClick="set_c3(this)">
femaleicon</p>
</form>
arnyinc
01-08-2003, 08:14 PM
Ok, you are using radio buttons, not checkboxes. They are designed to support exactly what you want to do without using any javascript. Just give them both the same name.
<input type="radio" name="sx" value="male">I am male<br>
<input type="radio" name="sx" value="female">I am female
ok,
I'm sorry to change but I'm working on it now :)
I've sorted best thing to do what I need is this:
<form name="myform">
<p> male
<input type="radio" name="sex" value="male" >
female
<input type="radio" name="sex" value="female" >
</p>
<p>
<input type="hidden" name="hiddenField" value="maleicon.gif">
maleicon </p>
</form>
where the hidden field take value from the selected radio button.
not exactly the same value but if male=maleicon.gif if female=femaleicon.gif
if you can solve that you are a GReat and apologize for changes..
scroots
01-08-2003, 09:11 PM
you just add an onclick something like
onClick="documnet.myform.hiddenfiled.value=femaleicon.gif"
to the female one and just have the defualt value for hiddenfiled as maleicon.gif
scroots
arnyinc
01-08-2003, 09:25 PM
Just to put it in code:
<form name="myform">
<p> male
<input type="radio" name="sex" value="male" onClick="document.myform.hiddenField.value='maleicon.gif'" checked>
female
<input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'">
</p>
<p>
<input type="hidden" name="hiddenField" value="maleicon.gif">
</p>
</form>
what intial value for the hiddenfield?
cause it remains ever maleicon.gif
thanx a lot for help
sorry it works fine!!!!
thanks again and good coding...
how can set at the same time 2 hiddenfields???
<input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'"; ="document.myform.hiddenField2.value='femaleicon2.gif'"; >
will this work??
thank
chrismiceli
01-08-2003, 10:29 PM
Originally posted by scsi
<input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'"; ="document.myform.hiddenField2.value='femaleicon2.gif'"; >
change it to
<input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'; document.myform.hiddenField2.value='femaleicon2.gif'>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.