Entry
How can i get an array that contains all checkboxes in document and submit them only if they are che
May 12th, 2004 02:23
Suban Asif, selene rebane,
By default, only those checkboxes are submitted which are checked.
Neverthless, below is code for the first part of your question:
var arr = new Array();
for ( var i = 0 ; i < document.myForm.elements.length; i++ ){
var elm = document.myForm.elements[i];
if ( elm.type == "checkbox" ){
arr[arr.length] = elm;
}
}
For the second part,
var toSubmit = true;
for( var i = 0; i < arr.length; i++){
var checkbox = arr[i];
if ( !checkbox.checked ) {
toSubmit = false;
break;
}
}
if ( toSubmit ) {
document.myForm.submit();
}