
Si tratta di una funzione che viene molto usata nelle webmail, per facilitare l’ utente nel selezionare i messaggi di posta e, con un click sottoporli ad una azione (ad esempio per segnarli come già letti, eliminarli, spostarli). Ecco come implementare questa funzionalità all’ interno di una web application.
Alla base dell’ esempio, c’e’ questa funzione Javascript che ho realizzato:
/*
MODE:
0 => Provide select inverse
1 => Ignore the value of checkboxes, all CHECKED
2 => Ignore the value of checkboxes, all UNCHECKED
*/
function checkAll(formName, checkboxListName, mode){
var formObj = document.forms[formName];
if(!formObj)
return;
var checkListObj = formObj.elements[checkboxListName];
if(!checkListObj)
return;
var checkListObjLength = checkListObj.length;
if(checkListObjLength == undefined)
checkListObjLength = 0;
for(var i = 0; i < checkListObjLength; i++){
if(mode == 0){ //select inverse
if(checkListObj[i].checked == true)
checkListObj[i].checked = false
else
checkListObj[i].checked = true;
}
else if (mode == 1){ //all checked
checkListObj[i].checked = true;
}
else if(mode == 2){ //all unchecked
checkListObj[i].checked = false;
}
}
}
RSS feed for comments on this post · TrackBack URI
Leave a reply