473,406 Members | 2,378 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,406 software developers and data experts.

Javascript to check checkboxes?

Hi all. I'm wondering if there's a way to have checkboxes become
selected without clicking the mouse. Perhaps if you rollover the
checkboxes, they could toggle checked and unchecked? Or perhaps you
could click-and-hold and then drag across a series of checkboxes to
select them?

Please let me know,
Sincerely,
Paul Rubin
pr****@equilter.com
Jul 20 '05 #1
5 1768
"Paul Rubin" <pr****@equilter.com> wrote in message
news:f9**************************@posting.google.c om...
Hi all. I'm wondering if there's a way to have checkboxes become
selected without clicking the mouse. Perhaps if you rollover the
checkboxes, they could toggle checked and unchecked? Or perhaps you
could click-and-hold and then drag across a series of checkboxes to
select them?

Please let me know,
Sincerely,
Paul Rubin
pr****@equilter.com

Like the following? Watch for word-wrap.

<html>
<head>
<title>checkme.htm</title>
<script language="javascript" type="text/javascript">
<!--
function mouser() {
var form = document.forms[0];
if (form.box1.checked) {
form.box1.checked = false;
} else {
form.box1.checked = true;
}
}
// -->
</script>
</head>
<body>
<form>
<input type="checkbox" name="box1" value="1" onmouseover="mouser()">
</form>
</body>
</html>
Jul 20 '05 #2
McKirahan wrote:

function mouser() {
var form = document.forms[0];
if (form.box1.checked) {
form.box1.checked = false;
} else {
form.box1.checked = true;
}
}


Or:

function mouser() {
var theBox = document.forms[0].elements['box1'];
theBox.checked = !theBox.checked;
}

Depending on which syntax you prefer...
JW

Jul 20 '05 #3
Thanks for your kind reply. How about if there are a whole bunch of
checkboxes, with names, p.1, p.2, p.3, etc ???

I hope this can be incorporated!
Sincerely,
Paul Rubin
pr****@equilter.com

"McKirahan" <Ne**@McKirahan.com> wrote in message news:<yZJHb.486016$Dw6.1425226@attbi_s02>...
"Paul Rubin" <pr****@equilter.com> wrote in message
news:f9**************************@posting.google.c om...
Hi all. I'm wondering if there's a way to have checkboxes become
selected without clicking the mouse. Perhaps if you rollover the
checkboxes, they could toggle checked and unchecked? Or perhaps you
could click-and-hold and then drag across a series of checkboxes to
select them?

Please let me know,
Sincerely,
Paul Rubin
pr****@equilter.com

Like the following? Watch for word-wrap.

<html>
<head>
<title>checkme.htm</title>
<script language="javascript" type="text/javascript">
<!--
function mouser() {
var form = document.forms[0];
if (form.box1.checked) {
form.box1.checked = false;
} else {
form.box1.checked = true;
}
}
// -->
</script>
</head>
<body>
<form>
<input type="checkbox" name="box1" value="1" onmouseover="mouser()">
</form>
</body>
</html>

Jul 20 '05 #4
"Paul Rubin" <pr****@equilter.com> wrote in message
news:f9**************************@posting.google.c om...
Thanks for your kind reply. How about if there are a whole bunch of
checkboxes, with names, p.1, p.2, p.3, etc ???

I hope this can be incorporated!
Sincerely,
Paul Rubin
pr****@equilter.com


The following does what you want.
(I've used JW's elegant approach.)
Watch for word-wrap.

<html>
<head>
<title>checkers.htm</title>
</head>
<body>
<form>
<input type="checkbox" name="p.1" value="One"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.2" value="Two"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.3" value="Three"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.4" value="Four"
onmouseover="this.checked=!this.checked">
</form>
</body>
</html>


Jul 20 '05 #5
Works like a charm!
Thank you,
Sincerely,
Paul Rubin
pr****@equilter.com

"McKirahan" <Ne**@McKirahan.com> wrote in message news:<czZHb.69570$VB2.136182@attbi_s51>...
"Paul Rubin" <pr****@equilter.com> wrote in message
news:f9**************************@posting.google.c om...
Thanks for your kind reply. How about if there are a whole bunch of
checkboxes, with names, p.1, p.2, p.3, etc ???

I hope this can be incorporated!
Sincerely,
Paul Rubin
pr****@equilter.com


The following does what you want.
(I've used JW's elegant approach.)
Watch for word-wrap.

<html>
<head>
<title>checkers.htm</title>
</head>
<body>
<form>
<input type="checkbox" name="p.1" value="One"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.2" value="Two"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.3" value="Three"
onmouseover="this.checked=!this.checked">
<input type="checkbox" name="p.4" value="Four"
onmouseover="this.checked=!this.checked">
</form>
</body>
</html>

Jul 20 '05 #6

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

Similar topics

2
by: john | last post by:
hi I am generating a set of dynamic checkboxes via php. I have to check that the uer should atleast check one checkbox. When there are more then 1 checkbox my javascript works but if there is...
4
by: Michael Champagne | last post by:
We have an application to where you can select/deselect all checkboxes in a checkbox array by clicking a 'master' checkbox at the top of the screen. This seems to work fine unless there is only...
4
by: Marc | last post by:
Is there a way to produce 3 radio buttons, which when one is selected, enables 11 check boxes which are otherwise disabled (greyed out)? EXAMPLE: Option 1 --Radio buttons Option 2 Option 3 ...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
0
by: Machi | last post by:
> let say i created nested repeaters in HTML page of a particular Web Form Parent repeater dubbed >> "parentRepeater", child Repeater dubbed "childRepeater" . Withi "parentRepeater" and...
5
by: Jimmy | last post by:
Hi I am trying to check whether checkboxes are checked in my user control. I have problems getting the right reference to the checkboxes: <%@ Page language="c#" Codebehind="WebForm2.aspx.cs"...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
13
by: Oleg Konovalov | last post by:
Hi, I am working on a web application which among other things uses DHTML, Java and Javascript. It populates web page based on the contents of the database (resultset), and next to each row...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.