View Full Version : Check All Checkbox

06-06-2003, 08:11 AM
I found a free script on checking all boxes with one click of select all checkbox. But i don't know how to alter it to fit my script.

<form name="frmOrders" action="pass.asp" method="post">
while not objrs.eof
<input type="checkbox" name="<%=j%>.stockitem" value="<%=objrs("ID")%>"><br>
<input type=checkbox name="selectall" value="" onClick="selectAll()">

<script language="Javascript">
function selectAll() {
if (document.frmOrders.countitems.value=="0") {} else
if (document.frmOrders.countitems.value=="1") {
} else {
for (var x=0; x<document.frmOrders.countitems.value; x++) {

stockitem.checked is not right in my javascript. how can i include the value of <%=j%>.stockitemi in the javascript?

06-06-2003, 09:17 AM
dont include that in your script, loop through all form elements and if the elementtype is CHECKBOX, then check it


var elem = document.forms["frmOrders"].elements;
for (i in elem) {
if (i.type == "checkbox" && (i.name.indexof("stockitem") > -1)){
i.checked = true;

this is not tested code, but it should give you an idea how to handle it

06-06-2003, 03:55 PM
Originally posted by carrera
I found a free script on checking all boxes with one click of select all checkbox. But i don't know how to alter it to fit my script.

A trick I use relies on declaring the checkboxes as an array of checkbox objects (just give them all the same name, just like radio buttons). Here's a sample...

<form action="">
<input name="scope" type="radio" onclick="setAll(this,true)">All
<input name="scope" type="radio" onclick="setSome(this)">Some
<input checked name="scope" type="radio" onclick="setAll(this,false)">None<br>
<input name="choice" type="checkbox" onclick="setSome(this)">Bees<br>
<input name="choice" type="checkbox" onclick="setSome(this)">Money<br>
<input name="choice" type="checkbox" onclick="setSome(this)">Psychology<br>
<input name="choice" type="checkbox" onclick="setSome(this)">Web Development<br>
<script type="text/javascript" language="javascript">
function setSome(chk)
var sum=0;
for(var i=0;i<choice.length;i++)sum+=(choice[i].checked?1:0);
scope[1].checked=(!scope[0].checked && !scope[2].checked);
function setAll(chk,state)
if(chk.checked)with(chk.form)for(var i=0;i<choice.length;i++)choice[i].checked=state;

Hopefully, you can adapt this script for your own application.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum