I have two JavaScript code snippets. These perform specific task when an 'Update' button is clicked.
I would like to merge them. Any help is appreciated.
JavaScript 1: When the button is clicked, it checks if at least one checkbox is selected:
function doUpdate(){
var c = document.getElementsByTagName('input');
for (var i = 0; i < c.length; i++) {
if (c[i].type == 'checkbox' && c[i].checked == true) {
// At least one checkbox is checked
document.holiDay.command.value= 'update';
document.holiDay.submit();
return true;
}
}
// Nothing has been checked
alert("Please identify what warehouses comply:");
return false;
}
JavaScript 2: When any checkbox is checked and update button is clicked, check all of them or uncheck all of them if any checkbox is unchecked; then perform the update feature:
function doUpdate(){
checked=false;
function All (holiDay) {
var all= document.getElementById('holiDay');
if (checked == false){
checked = true
}
else{
checked = false
}
for (var i =0; i < all.elements.length; i++){
all.elements[i].checked = checked;
}
}
//after checked or unchecked all checkboxes then submit the form and other functionality
document.holiDay.command.value= 'update';
document.holiDay.submit();
return true;
}