I feel like I should know the answer but I just can't get it. I have a big form and some questions have checkboxes. I need to be able to loop through each of the checkboxes for that particular question and for the ones that're checked, I need to store in an array. I'm forced to use javascript due to working with existing code. here's one example I've tried:
<input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_0" value="Bareboat charters">
<input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_1" value="charters">
<input type="checkbox" name="CAT_Custom_15" id="CAT_Custom_15_2" value="Ferry">
<script>
var theForm = document.getElementById( 'OMRForm' );
var i;
var selectArray = []; //initialise empty array
for (i = 0; i < theForm.CAT_Custom_15.length; i++) {
if(theForm.CAT_Custom_15.elements[i].type == 'checkbox'){
if(theForm.CAT_Custom_15.elements[i].checked == true){
selectArray.push(theForm.CAT_Custom_15.elements[i].value);
alert(theForm.CAT_Custom_15.elements[i].value);
}
}
}
</script>
I've stared at this so long it that I'm sure i've made a mistake somewhere. Please help!