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
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating a multidimensional array (nXn) matrix using javascript

    $(function(){
    var tableLenght = new Array();
    $('#matrix').click(function(){
    var counter = 0;
    $("#riskForm tr").each(function(){
    //ignores the header of the table (the title)
    if(counter >=1){
    tableLenght.push($(this).closest('tr').children("td:eq(1)").text());
    }
    counter++;
    });

    // get unique attributes of in our table
    var uniqueList = new Array();
    //push first element onto list
    uniqueList.push(tableLenght[0]); //pushes current elem onto the array
    var cur = tableLenght[0]; //sets first element by default
    for(var i = 1; i < tableLenght.length; i++){ //loops through the whole lenght of our array
    if(cur != tableLenght[i]){//checks if the current is not same as the next one
    cur = tableLenght[i]; //sets the new elemt
    uniqueList.push(tableLenght[i]); //pushes onto the array
    }
    }
    alert(uniqueList); //alerts only the unique table rows in the tableLenght array
    var myArray = new Array(uniqueList);

    for (var i = 0; i < uniqueList; i++) {
    myArray[i] = new Array(uniqueList);
    for (var j = 0; j < uniqueList; j++) {
    myArray[i][j] = '';
    }
    }
    });

    //to show/get the values of selected radio buttons
    function showValues() {
    var fields = $( ":input").serializeArray();
    $( "#results" ).empty();
    jQuery.each( fields, function( i, field ) {
    $( "#results" ).append( field.value + " " );
    });
    }

    $( ":checkbox, :radio" ).click( showValues );
    showValues();
    $('#display').click(function (n) {
    document.location.href="trialIndex.php"
    });
    });

    Your help is much appreciated!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,456
    Thanks
    0
    Thanked 632 Times in 622 Posts
    And your question is?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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