Solved

Check a checkbox and then automatically other checkbox

Posted on 2008-10-28
9
281 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:nkoriginal
9 Comments
 
LVL 7

Expert Comment

by:bluV11t
ID: 22822179
Hi!
Could you please post your html so I have somthing to start with?
0
 
LVL 7

Expert Comment

by:aamodt
ID: 22822251
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
 
LVL 82

Expert Comment

by:hielo
ID: 22822574
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22822610
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
 
LVL 5

Author Comment

by:nkoriginal
ID: 22822646
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
 
LVL 82

Expert Comment

by:hielo
ID: 22822683
use my second suggestion. Just supply the id of the radio button that you wish to check on the second column.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22822700
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
 
LVL 5

Author Comment

by:nkoriginal
ID: 22822774
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
 
LVL 82

Expert Comment

by:hielo
ID: 22823621
>>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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Date on a table 16 37
Video Tutorial help 2 40
[form-control] Retain values after a POST action 21 39
Ajax on ASP 2 43
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question