Automatically check/uncheck multiple checkboxes
Last post was 28 Oct 2008 at 00:30
-
Hi!
In my program, I have multiple check boxs.(more the 10) But i give rights to select 2 check boxs, If i select more then 2 check boxs, I want to display alert message. Please any one post me modle program in ASP and javascript. Please very very urgent.... any only help me...
My javascript program: (Its not working)
function myFunction()
{
var canSu = true;
//Check how many checkboxes are on the form
boxes = document.frmUpdate.chkboxes.length
//Check for all the checkboxes on the form using the loop
var chkCnt=0;
for (i = 0; i < boxes; i++)
{
if (document.frmUpdate.chkboxes[i].checked)
{
chkCnt++;
}
}
if(chkCnt >= 2)
{
return false;
}
return true;
}
By Susan.
-
hi Susan,
Keep the autopost back property of checkbox to true. and whenever a checkobox is checked then use a looping statement(like: for loop) to check the state of all the checkboxs on your form. And keep a counter variable to count the no. of check boxes checked. If the counter increases than 2 then display the message.
To scan throught all the checkboxes on your form, lets say the check boxes are on a panel then:
foreach(control c in panel.controls)
{
if(c is checkbox)
{
checkbox cbx = new checkbox();
cbx = panel.findcontrol(c.id);
if(cbx.checked.equals(true)
{
// increment the counter
// check if counter is less than 2 or not
// perform the necessary task
}
}
}
Regards,
Royal
-
What I need is simple: I’d like a checkbox that UNCHECKS the other checkboxes in a single array.
I'd be grateful if someone can suggest a short javascript that would do this without affecting other checkboxes or radio buttons within the same form.
Post a reply
Enter your message below
Sign in or Join us (it's free).