Hi,
I'm not a javascript expert and tried to loop through an array like so:
for(var x=0;x<40;x++){
array1[x]= array2['word'+x];
}
My goal is to avoid typing 40+ lines of code to get the following result:
array1[0] = array2['word0'];
array1[1] = array2['word1'];
array1[2] = array2['word2'];
etc etc.....
As you've probably guessed, it isn't working. 🙁
Any idea why and how to make it work?
My latest attempt is:
<script language="JavaScript">
function selectAll(){
var chkBoxes = new Array();
var frm = document.forms['choices'];
for(var x=0;x<40;x++) {
var y = x + 1;
string termIndex = "term" + y;
chkBoxes[x] = frm.elements['termIndex'];
chkBoxes[x].checked = true;
}
}
</script>
I've declaring/not declaring different vaiables in all sorts of ways but to no avail.
Here is the working code:
function selectAll() {
var chkBoxes = new Array();
var frm = document.forms['geometry_pic_dic'];
chkBoxes[0] = frm.elements['term1'];
chkBoxes[1] = frm.elements['term2'];
chkBoxes[2] = frm.elements['term3'];
chkBoxes[3] = frm.elements['term4'];
chkBoxes[4] = frm.elements['term5'];
chkBoxes[5] = frm.elements['term6'];
chkBoxes[6] = frm.elements['term7'];
chkBoxes[7] = frm.elements['term8'];
chkBoxes[8] = frm.elements['term9'];
chkBoxes[9] = frm.elements['term10'];
for(var y=0;y<chkBoxes.length;y++) {
chkBoxes[y].checked = true;
}
}