Select all / Clear All checkbox in JavaScript

Select all / Clear All checkbox in JavaScript > > >

just copy paste the JS function and Call the function using buttons ..

The function has three parametrs

Formname–Name of the form

Fieldname–Name of the checkbox array

Checkvalue–Set to “TRUE” for select all and Set to “FALSE” for clear all

<script type=”text/javascript” > <!–
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;

var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;

var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;

}
< /script >

eg …

<input type=‘button’ name=‘check’ value=’select all’ onclick=“SetAllCheckBoxes(’f1',’ch[]‘,true);” >

<input type=‘button’ name=‘clear’ value=‘clear all’ onclick=“SetAllCheckBoxes(’f1',’ck[]‘,false);” >


Leave a Reply

Popular Posts

Total Pageviews