473,395 Members | 2,222 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/uncheck a number of checkboxes by clicking an image

Hi,

I want to check or uncheck a number of checkboxes by clicking an image.

My html code is given below:
[HTML]

<TABLE>
<TR>
<TD>
<div id = "checkdiv" >
<img src = "/images/check.jpg" />
</div>
</TD>
</TR>
<TR>
<TD>
<input type = "checkbox" name = "del">
</TD>
</TR>
<TR>
<TD>
<input type = "checkbox" name = "del">
</TD>
</TR>
</TABLE>

[/HTML]

Now if i click image or div all the checkboxes should be checked and again if i click that image or div all the checkboxes should be unchecked.
Jul 24 '08 #1
3 3353
maminx
77
i think you must make another event.
For example, onclick for check the checkbox and another event for uncheck the chekbox..


But hope this can usefull...

first, change your "a" tag with this

[HTML]<a href="#" onclick="javascript:setBox();" ><img src="/images/check.jpg"></a>[/HTML]

second. Better use a unique name for checkbox.
The first checkbox may named "del1", and second checbox goes to "del2".
Of course this is depends with your need

than after the body, make the script

[HTML]<script type="text/javascript">
function setBox() {
var form = document.forms[0];
form.del1.checked=true;
form.del2.checked=true;
}
</script>[/HTML]

and as i said, to uncheck the checbox, i think you need another event,,

thanks..

kind regards,
maminx
Jul 24 '08 #2
gits
5,390 Expert Mod 4TB
the javascript: part in the following line is never needed:

Expand|Select|Wrap|Line Numbers
  1. onclick="javascript:setBox();"
the following:

Expand|Select|Wrap|Line Numbers
  1. onclick="setBox();"
is always enough ...

kind regards
Jul 24 '08 #3
acoder
16,027 Expert Mod 8TB
Make one function which checks/unchecks all checkboxes and pass it a parameter to determine whether it should be checked or not, e.g.
Expand|Select|Wrap|Line Numbers
  1. function checkUncheckBoxes(check) {
  2.   var chk = document.getElementsByName(chckboxname);
  3.   for (i = 0; i< chk.length; i++) {
  4.     chk[i].checked = check;
  5.   }
  6. }
Jul 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: pw | last post by:
Hi, I need to create a function in javascript to check or uncheck all checkboxes in a form. From what I understand, I can do this either by specifying the name of the check box fields such as: ...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
4
by: lemat | last post by:
Hi, I use a radio button form in which users can select a color by clicking on a image. I would like this image to change to another one when it's chosen. (image with a "Chosen" Stamp in the...
4
by: chengsi | last post by:
Hi, I have a "continuous" subform which is linked to a table which has a checkbox field. I would like to create a Check All/Uncheck All checkbox control that both checks and disables the...
12
by: swebster | last post by:
I need to zero in on a specific section of my jsp form during a hide to uncheck the checkboxes in that section. Currently, anything I try either unchecks all checkboxes on the form or doesn't work...
3
by: Ryanfromscotland | last post by:
Hey there everyone, this is my first post so be nice :-) I have wrote quite a bit so the actual question is written out at the end if you want to skip on and see if you can answer it without the rest...
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
14
by: dragon52 | last post by:
Hi Everyone, Not sure the following is possible to do. The standard MS Access user interface has checkboxes on a number of menu pages, such as Tools/Options/View. I have been asked to find a...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.