I am wondering if it is possible to have a dynamic counter
in a javascript function
I need to loop through that set of checkboxes, and check them or uncheck them. The checkboxes vary in amount and where on the page they start
I have the following code for this:
The problem is that there isn't always ten check boxes on the page , and also the loop does not always start at the first check box on the page. So I need to find a way to dynamically set the initialisation of the counter, and also the i<n number to loop through
eg:
to start at the fifth of ten check boxes:
needs to be set to: for(var i=5;i<10;i++)
to start at the eighth of seventeen check box
needs to be set to: for(var i=8;i<17;i++)
I would like to achieve this with the one function if possible
I already have the following code
(from this forum) to build a dynamic array:
Any help would be appreciated
in a javascript function
I need to loop through that set of checkboxes, and check them or uncheck them. The checkboxes vary in amount and where on the page they start
I have the following code for this:
Code:
function WLToggle() {
if (document.frmSearch.elements['chkWLToggle'].checked==false) {
for(var i=0;i<10;i++)
document.frmSearch.elements[i].checked=false;
}
else {
for(var i=0;i<10;i++)
document.frmSearch.elements[i].checked=true;
}
}
The problem is that there isn't always ten check boxes on the page , and also the loop does not always start at the first check box on the page. So I need to find a way to dynamically set the initialisation of the counter, and also the i<n number to loop through
eg:
to start at the fifth of ten check boxes:
needs to be set to: for(var i=5;i<10;i++)
to start at the eighth of seventeen check box
needs to be set to: for(var i=8;i<17;i++)
I would like to achieve this with the one function if possible
I already have the following code
(from this forum) to build a dynamic array:
Code:
<HTML>
<HEAD>
<TITLE> Checkbox </TITLE>
<script>
function buildarray(frm) {
//alert(frm.elements.length);
//alert(frm.elements[0].type);
arr = new Array;
for (elm=0; elm<frm.elements.length; elm ++) {
if (frm.elements[elm].type == "checkbox") arr[elm] = frm.elements[elm].id;
alert(arr[elm]);
}
}
</script>
</HEAD>
<form name="myForm">
<input type=checkbox name='buildarray' id='buildarray' onclick="buildarray(document.myForm)"></td>
<input type="checkbox" id="cbo3706" name="cbo3706">cbo3706<br>
<input type="checkbox" id="cbo3707" name="cbo3707">cbo3707<br>
<input type="checkbox" id="cbo3708" name="cbo3708">cbo3708<br>
<input type="checkbox" id="cbo3709" name="cbo3709">cbo3709<br>
<input type="checkbox" id="cbo3710" name="cbo3710">cbo3710<br>
<input type=checkbox name='buildarray' id='buildarray' onclick="buildarray(document.myForm)"></td>
<input type="checkbox" id="cbo3711" name="cbo3711">cbo3711<br>
<input type="checkbox" id="cbo3712" name="cbo3712">cbo3712<br>
<input type="checkbox" id="cbo3713" name="cbo3713">cbo3713<br>
<input type="checkbox" id="cbo3714" name="cbo3714">cbo3714<br>
<input type="checkbox" id="cbo3715" name="cbo3715">cbo3715<br>
</form>
</BODY>
</HTML>
Any help would be appreciated