Solved

Check a checkbox and then automatically other checkbox

Posted on 2008-10-28
9
280 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

825 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