Multiple Checkboxes

D

Dave

I got a total of 8 checkboxes, but only want to allow a
total of three to be checked, can be any three
checkboxes. Any thoughts???

Thanks

Dave
 
K

Kevin Spencer

Custom JavaScript validation. Count the checkboxes that are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
D

Dave

Thanks Kevin Works great!

Dave
-----Original Message-----
Custom JavaScript validation. Count the checkboxes that are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

I got a total of 8 checkboxes, but only want to allow a
total of three to be checked, can be any three
checkboxes. Any thoughts???

Thanks

Dave


.
 
D

Dave

Kevin I had it working, ut now i'm getting an Object
error...this is what I got

function chkCount()
{
var i = 0;

if (document.frmShortService.ChkLH.checked) i++;
....

if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return(false);
}
}
LH <input type="checkbox" name="chkLH" value="YES"
onclick="chkCount()">
....
-----Original Message-----
Thanks Kevin Works great!

Dave
-----Original Message-----
Custom JavaScript validation. Count the checkboxes that are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

I got a total of 8 checkboxes, but only want to allow a
total of three to be checked, can be any three
checkboxes. Any thoughts???

Thanks

Dave


.
.
 
D

Dave

LOL...Nevermind I got it working now...I had something
stupid going on...your code works perfect...agian thanks!

Dave
-----Original Message-----
Kevin I had it working, ut now i'm getting an Object
error...this is what I got

function chkCount()
{
var i = 0;

if (document.frmShortService.ChkLH.checked) i++;
....

if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return(false);
}
}
LH <input type="checkbox" name="chkLH" value="YES"
onclick="chkCount()">
....
-----Original Message-----
Thanks Kevin Works great!

Dave
-----Original Message-----
Custom JavaScript validation. Count the checkboxes
that
are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

I got a total of 8 checkboxes, but only want to
allow
.
 
C

Chris

How could you disable the remaining checkboxes that
aren't checked after three have been checked?

Chris
-----Original Message-----
LOL...Nevermind I got it working now...I had something
stupid going on...your code works perfect...agian thanks!

Dave
-----Original Message-----
Kevin I had it working, ut now i'm getting an Object
error...this is what I got

function chkCount()
{
var i = 0;

if (document.frmShortService.ChkLH.checked) i++;
....

if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return(false);
}
}
LH <input type="checkbox" name="chkLH" value="YES"
onclick="chkCount()">
....
-----Original Message-----
Thanks Kevin Works great!

Dave
-----Original Message-----
Custom JavaScript validation. Count the checkboxes that
are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

message
I got a total of 8 checkboxes, but only want to
allow
a
total of three to be checked, can be any three
checkboxes. Any thoughts???

Thanks

Dave


.

.
.
.
 
K

Kevin Spencer

document.forms[0].CHK1.disabled = (true);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Chris said:
How could you disable the remaining checkboxes that
aren't checked after three have been checked?

Chris
-----Original Message-----
LOL...Nevermind I got it working now...I had something
stupid going on...your code works perfect...agian thanks!

Dave
-----Original Message-----
Kevin I had it working, ut now i'm getting an Object
error...this is what I got

function chkCount()
{
var i = 0;

if (document.frmShortService.ChkLH.checked) i++;
....

if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return(false);
}
}
LH <input type="checkbox" name="chkLH" value="YES"
onclick="chkCount()">
....
-----Original Message-----
Thanks Kevin Works great!

Dave
-----Original Message-----
Custom JavaScript validation. Count the checkboxes that
are checked. If
there are more than 3, alert the user and return false.

var i = 0;
if (document.forms[0].CHK1.checked) i++;
if(document.forms[0].CHK2.checked) i++;
....
if (i > 3)
{
alert("Only 3 Checkboxes can be checked");
return (false);
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

message
I got a total of 8 checkboxes, but only want to allow
a
total of three to be checked, can be any three
checkboxes. Any thoughts???

Thanks

Dave


.

.

.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top