Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2002, 07:40 AM   PM User | #1
Denis
New to the CF scene

 
Join Date: Jul 2002
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Denis is an unknown quantity at this point
Question How to => array1[x] = array2 ['word'+x]

Hello,

I'm a newbie at javascript and trying to populate an array using the following method:

for (x = 1; x < 41; x++){
var y = x+1;
array1[x] = array2 ['word'+y];
}

so has to shorten the code from:

array1[0] = array2 ['term1'];
array1[1] = array2 ['term2'];
array1[2] = array2 ['term3'];
etc etc ....

is this possible in javascript? (my numerous attempt have failed so far)?
is ther an equivalent to the php "${"term".$x}"?


this is part of the original working script:

function selectAll() {
var chkBoxes = new Array();
var frm = document.forms['choices1'];
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'];
chkBoxes[10] = frm.elements['term11'];
chkBoxes[11] = frm.elements['term12'];
chkBoxes[12] = frm.elements['term13'];
chkBoxes[13] = frm.elements['term14'];
chkBoxes[14] = frm.elements['term15'];
chkBoxes[15] = frm.elements['term16'];
chkBoxes[16] = frm.elements['term17'];
chkBoxes[17] = frm.elements['term18'];
chkBoxes[18] = frm.elements['term19'];
chkBoxes[19] = frm.elements['term20'];
chkBoxes[20] = frm.elements['term21'];
chkBoxes[21] = frm.elements['term22'];
chkBoxes[22] = frm.elements['term23'];
chkBoxes[23] = frm.elements['term24'];
chkBoxes[24] = frm.elements['term25'];
chkBoxes[25] = frm.elements['term26'];
// etc etc...... up to 45
for(var y=0;y<chkBoxes.length;y++) {
chkBoxes[y].checked = true;
}
}

this script, as you surely guessed, automatically "tick" 45 checkboxes by clicking a button inside the "choices1" form.

any help would be greatly appreciated.

Last edited by Denis; 07-07-2002 at 07:45 AM..
Denis is offline   Reply With Quote
Old 07-08-2002, 05:02 AM   PM User | #2
Denis
New to the CF scene

 
Join Date: Jul 2002
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Denis is an unknown quantity at this point
Smile

Thanks a lot Dave, nice snippet of code that also gives me more insight into javascript.
Denis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11 PM.


Advertisement
Log in to turn off these ads.