By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Javascript to check checkboxes?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.