Putting form values in array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cainnech
    New Member
    • Nov 2007
    • 132

    Putting form values in array

    Hi,

    In one of my scripts I'm having difficulties adding fromvalues to an array.

    For testing purposes I made an array like this:
    Code:
    var mijnlotto1 = [19,23,27,32,34,41];
    This way my script works.
    However I want to fill in the array dynamically. So I want to create the array called mijnlotto1 from input boxes that are on my page. So I did:
    Code:
    var mijnlotto1 = new Array();
    mijnlotto1[0]=document.combinatie1.nr1.value;
    mijnlotto1[1]=document.combinatie1.nr2.value;
    mijnlotto1[2]=document.combinatie1.nr3.value;
    mijnlotto1[3]=document.combinatie1.nr4.value;
    mijnlotto1[4]=document.combinatie1.nr5.value;
    mijnlotto1[5]=document.combinatie1.nr6.value;
    where combinatie1 is the name of the form and nr1 to nr6 are the names of the input boxes. However using this method the script won't work.

    The array mijnlotto1 is being used to compare to another array. So I'm guessing the format of mijnlotto1 is not correct. However I'm not sure what the right format would be.

    The other array is fixed and is created like this:
    Code:
    lotto[0] = new lottohistory('4-2-1978', '6', '17', '30', '31', '35', '37', '15', '460171.2', '0', '0', '18', '1701', '35206', '1.24');
    Any help would be appreciated.
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi dude, dont do that in that way rather do like this

    [HTML]<script language="javas cript">
    var myArray=[];
    function assign()
    {
    myArray.push(do cument.getEleme ntById('Ele1'). value);
    }
    </script>[/HTML]

    Here Ele1 is the id given to your text box

    Ex. <input type="text" id="Ele1">

    Do like this surely your code will work;

    Regards
    Ramanan Kalirajan

    Comment

    Working...