Javascript-Create Matrix from Dynamic Form Help-Please?

Discussion in 'JavaScript' started by lukezli, Nov 2, 2010.

  1. #1
    Hey guys. I am trying to make a determinant calculator, for any size. I have made an algorithm for the determinant that is recursive (tested in java) and just need to create an array in javascript that allows me to use the algorithm. I dynamically create the table using this code:
    <HTML>
    <HEAD>
    <TITLE>Dynamically add Textbox, Radio, Button in html Form using JavaScript</TITLE>
    <SCRIPT language="javascript">
    function add(num) {
    var foo = document.getElementById("fooBar");
    var bk = document.createElement("br");

    //Create an input type dynamically.
    foo.appendChild(bk);
    for (i=1; i<=num; ++i) {
    for (j=1; j<=num; ++j) {
    var element = document.createElement("input");


    //Assign different attributes to the element.
    element.setAttribute("type", "input");
    element.setAttribute("value", "0");
    element.setAttribute("size", "5");
    element.setAttribute("name", "val");

    //Append the element in page (in span).
    foo.appendChild(element);
    }
    bk = document.createElement("br");
    foo.appendChild(bk);
    }

    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM>
    <H2>Dynamically add element in form.</H2>
    Select the element and hit Add to add it in form.
    <BR/>

    <INPUT type="text" name="col" value="3"/>
    <INPUT type="button" value="Add" onclick="add(document.forms[0].col.value)"/>
    <BR><BR>
    <span id="fooBar">&nbsp;</span>

    </FORM>
    </BODY>
    </HTML>

    but I don't know where to go to there. I can't seem to access the values for the forms: can you help me please? Thanks!
     
    lukezli, Nov 2, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    store in a multi-dimensional array (like myarray[0][3]) kind of like [row][column].. or just all in a single dimensional array?
     
    camjohnson95, Nov 7, 2010 IP
  3. lukezli

    lukezli Greenhorn

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    hey! nevermind i solved it myself. Used a textbox instead
     
    lukezli, Nov 8, 2010 IP