Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 08:45 AM.

  • #2
    New to the CF scene
    Join Date
    Jul 2002
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks a lot Dave, nice snippet of code that also gives me more insight into javascript.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •