473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to check a checkbox using Javascript

<script>
function CheckChange()
{
var mycheck = document.getElementById('test');
mycheck.check = true;
}
</script>

<body>
<form id="form1" runat="server">
<asp:CheckBox ID="test" runat="server" name="test" />
<asp:CheckBox ID="CheckBox1" onclick="CheckChange()"
runat="server" />
</form>
</body>
</html>
I am trying to make it so that checking one check box checks another
using no postbacks (so basically that means using Javascript). Above
is my code, and for some reason it just doesn't work. Any ideas?

Btw instead of the above javascript, I'd rather write "test.check =
true" but that fails and Firefox's error console says "test is not
defined"

Thanks,
Amit

Feb 1 '07 #1
2 18244
"AmitKu" <am****@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
I am trying to make it so that checking one check box checks another
using no postbacks (so basically that means using Javascript). Above
is my code, and for some reason it just doesn't work. Any ideas?
The checkbox property is 'checked', not 'check' e.g. mycheck.checked = true;
Feb 1 '07 #2
Hi Amit,

In addition to Mark's reply use control.ClientID property, don't set name
attribute directly because it is used internally for checkbox state retrival:
<script type="text/javascript">
function CheckChange()
{
var mycheck = document.getElementById('<%=test.ClientID %>');
mycheck.checked = true;
}
</script>
<asp:CheckBox ID="test" runat="server"/>
<asp:CheckBox ID="CheckBox1" onclick="CheckChange()" runat="server" />

--
Milosz
"AmitKu" wrote:
<script>
function CheckChange()
{
var mycheck = document.getElementById('test');
mycheck.check = true;
}
</script>

<body>
<form id="form1" runat="server">
<asp:CheckBox ID="test" runat="server" name="test" />
<asp:CheckBox ID="CheckBox1" onclick="CheckChange()"
runat="server" />
</form>
</body>
</html>
I am trying to make it so that checking one check box checks another
using no postbacks (so basically that means using Javascript). Above
is my code, and for some reason it just doesn't work. Any ideas?

Btw instead of the above javascript, I'd rather write "test.check =
true" but that fails and Firefox's error console says "test is not
defined"

Thanks,
Amit

Feb 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Edo van der Zouwen | last post by:
It's quite easy in Php: <?php $language = $_SERVER; $language_short = substr($taal,0,2); echo $language_short; ?>
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I have two checkboxes in each row of a grid. One for Modify and another one for View. If I click Modify the View should get automatically checked and should be disabled. Earlier I did this in...
1
by: datttanand | last post by:
how handle on check event in checkbox using javascript?
0
by: itsenthil | last post by:
Hi... I want change the color panel if i click checkbox i.e placed inside the panel (User Control)
2
by: itsenthil | last post by:
This is my UserControl(ascx) coding, it is not working plz help me to rectify the error.....what is wrong in that one..... <%@ Control Language="vb" AutoEventWireup="false"...
6
by: lucoin | last post by:
Hello guys, I met a problem about php and javascipt For a tickets booking system, when a customer search for flights from one city, so in the data base there should be many routes to different...
1
by: spiderman2 | last post by:
When the page is first accessed, certain HTML elements are dynamically created. The checkboxes all have the name "chkBox". There is a special "checkAll" checkbox which when checked or unchecked, does...
7
by: kikz4life | last post by:
Hi everyone. Im trying to optimize a website. But im stuck with this code here. My problem is when i check/uncheck the checkbox it took 5-6 sec just by clicking it. Could anyone help me rewrite this...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.