How to input values to 2D array using two for loops and get back using same way.. (I am going to code a simulator for matrices addition)...
I made matrices by using tables and text-boxes
this is my code:
declaration:
var matA = new Array(2);
var matB = new Array(2);
var matAns = new Array(2);
for(i=0; i<2; i++)
{
matA[i] = new Array(2);
matB[i] = new Array(2);
matAns[i] = new Array(2);
}
Code (Input Data form :
function getValueFromMatA()
{
for(r=0; r<2; r++)
{
for(c=0; c<2; c++)
{
matA[r,c]=parseInt(document.getElementById('nodeA'+r+''+c).value);
}
}
}
function getValueFromMatB()
{
for(r=0; r<2; r++)
{
for(c=0; c<2; c++)
{
matB[r,c]=parseInt(document.getElementById('nodeB'+r+''+c).value);
}
}
}
Code: Output(In this i can't get matAns[0,0] value and matAns[0,1] value. it gives me always matAns[1,0] value and matAns[1,1]
function addMaAMatB()
{
for(r=0; r<2; r++)
{
for(c=0; c<2; c++)
{
matAns[r,c] = matA[r,c]+matB[r,c];
}
}
}
function printMatAns()
{
for(r=0; r<2; r++)
{
for(c=0; c<2; c++)
{
alert(matAns[r,c]);
}
}
}
Please help me... where am I wrong??