i am having problems with checkboxes. If user clicks 'All", then all the checkboxes will be selected. if user clicks on "None", then all the checkbox will be unchecked. This works only when the user select 2 of more checkboxes to delete. If the user selects only one checkbox, the alert will keep coming out.

my script as follow:

function checkAll(field) {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
}
function unCheckAll(field) {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
}
function checkCheckbox(field) {
if (field != null) {
count = 0;
for (i = 0; i < field.length; i++) {
if (field[i].checked == true) {
count++;
}
}
if (count == 0) {
alert("Please check at least one itemto delete");
return false;
} else {
var answer = confirm("You are about to delete the following item(s)");
if (answer) {
window.location="delete_item.jsp";
}
return true;
}
}
return false;
}


on the page i have the following :

Select: <a href="javascript:checkAll(document.delete_item.select_delete)"><u>All</u></a> , <a href="javascript:unCheckAll(document.delete_item.select_delete)"><u>None</u></a>