Hi Everyone,
i have a query regarding checkboxes.
i have got a 'check all' checkbox on my form but what i need is to uncheck all if the check all is not checked

This is the check all script

function checkAll(field) {
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}

and i'm calling it via

<input type="checkbox" name="CheckAll" onclick="checkAll(document.myform['delete[]'])" />

Any help would be great.

Cheers...

you can try this

function checkAll(field) {
if(document.myform.CheckAll.checked)
{
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}
else
{
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}
}

you can try this

function checkAll(field) {
if(document.myform.CheckAll.checked)
{
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}
else
{
	for (i = 0; i < field.length; i++)
	field[i].checked = true;
}
}

Thanks for the reply,
Unfortunatly that didn't work but not to worry, i managed to find a code that did work for me. Thanks for taking the time.

Can you share it with us?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.