Check a checkbox and then automatically other checkbox

I've two columns both columns have this options

Column 1                YES              NO
xxxxxx                chechbox   chechbox

Column 2                YES              NO
yyyyyyyyy          chechbox   chechbox

I want a function an javascript, when I click YES or NO in column 1, automatically check YES or NO (depends what I clicked in column1).

See my screenshot

Thanks
checkbox.gif
LVL 5
nkoriginalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bluV11tCommented:
Hi!
Could you please post your html so I have somthing to start with?
0
aamodtCommented:
if (document.frmTest.CHKBOX_1.Value == Y)
{
document.frmTest.CHKBOX_2.Checked;
}

dont know exactly.  not so good in javascript but giving you some clue to how to do it.

on the form you will call the function over by onClick(); or something
0
hieloCommented:
try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
</head>
<body>
<form>
	<table>
		<tr><td><input type="radio" name="col1row1" value="yes" onclick="col2row1[0].checked=true;"/>Yes<input type="radio" name="col1row1" value="no" onclick="col2row1[1].checked=true;"/>No</td><td><input type="radio" name="col2row1" value="yes"/>Yes<input type="radio" name="col2row1" value="no"/>No</td></tr>
		<tr><td><input type="radio" name="col1row2" value="yes" onclick="col2row2[0].checked=true;"/>Yes<input type="radio" name="col1row2" value="no" onclick="col2row2[1].checked=true;"/></td><td><input type="radio" name="col2row2" value="yes"/>Yes<input type="radio" name="col2row2" value="no"/>No</td></tr>
	</table>
</form>
</body>
</html>

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

hieloCommented:
here's an alternative:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
<script>
function checkIt(e)
{
 document.getElementById(e).checked=true;
}
</script>
</head>
<body>
<form>
	<table>
		<tr><td><input type="radio" name="col1row1" value="yes" onclick="checkIt('col2row1_yes')"/>Yes<input type="radio" name="col1row1" value="no" onclick="checkIt('col2row1_no')"/>No</td><td><input type="radio" name="col2row1" id="col2row1_yes" value="yes"/>Yes<input type="radio" name="col2row1" id="col2row1_no" value="no"/>No</td></tr>
		<tr><td><input type="radio" name="col1row2" value="yes" onclick="checkIt('col2row2_yes')"/>Yes<input type="radio" name="col1row2" value="no" onclick="checkIt('col2row2_no')"/></td><td><input type="radio" name="col2row2" id="col2row2_yes" value="yes"/>Yes<input type="radio" name="col2row2" id="col2row2_no" value="no"/>No</td></tr>
	</table>
</form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nkoriginalAuthor Commented:
Thanks Guys for your fast help.  (I said checkbox but im using radio, Sorry, but it's doesn't matter, right)

Hielo I tried your way but i dont know what is not working.
Here is my code

(this my radio in the first column)
 
    <td><input type="radio" name="bt1_01_chkctherapy" id="bt1_01_chkctherapy"  value="1" onClick="bt1_01_chkctherapyst.checked=true;"></td>

This is the second column, row 1. I suppose to be checked when I checked 1 column row 1

    <td><div align="center"><input name="bt1_01_chkctherapyst" id="bt1_01_chkctherapyst" type="radio" value="1"></td>

What's wrong??
thanks
0
hieloCommented:
use my second suggestion. Just supply the id of the radio button that you wish to check on the second column.
0
hieloCommented:
assuming your radio buttons on the second column have the same name, this:
<td><input type="radio" name="bt1_01_chkctherapy" id="bt1_01_chkctherapy"  value="1" onClick="bt1_01_chkctherapyst.checked=true;"></td>
 
should have been:
<td><input type="radio" name="bt1_01_chkctherapy" id="bt1_01_chkctherapy"  value="1" onClick="bt1_01_chkctherapyst[0].checked=true;"></td>

Open in new window

0
nkoriginalAuthor Commented:
Hielo, your second option it worked good.
But I need to change my ID in each input and I can't do that, because I need to keep the same ID for the same input name

Here is the way is worked
    <td><div align="center"><input name="bt1_01_chkctherapyst" id="bt1_01_chkctherapyst1" type="radio" value="1"></td>
    <td><div align="center"><input name="bt1_01_chkctherapyst" id="bt1_01_chkctherapyst2" type="radio" value="0" checked ></td>

but I need to keep in this way

    <td><div align="center"><input name="bt1_01_chkctherapyst" id="bt1_01_chkctherapyst" type="radio" value="1"></td>
    <td><div align="center"><input name="bt1_01_chkctherapyst" id="bt1_01_chkctherapyst" type="radio" value="0" checked ></td>

is any solution to this??
0
hieloCommented:
>>because I need to keep the same ID
You NEED to keep the same NAME, but NOT the ID. As a matter of fact, the ID MUST be unique throughout the whole page.

On another note, in "the rapist" you misspelled "rapist". You used a "y" instead of an "i"
bt1_01_chkctherapyst
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.