pentagrant,
<script>
function Determinant(A)
{
var n = A.length, subA = [], detA = 0;
if (n==1) return A[0][0];
if (n==2) return (A[0][0]*A[1][1]-A[0][1]*A[1][0]);
if (n==3)
{ return ((A[0][0]*A[1][1]*A[2][2]+A[0][1]*A[1][2]*A[2][0]+A[0][2]*A[1][0]*A[2][1])
-(A[0][0]*A[1][2]*A[2][1]+A[0][1]*A[1][0]*A[2][2]+A[0][2]*A[1][1]*A[2][0]));
}
for (var i=0; i<n; i++)
{ for (var h=0; h<n-1; h++) subA[h]=[];
for (var a=1; a<n; a++)
{ for (var b=0; b<n; b++)
{ if (b<i) subA[a-1][ b ] = A[ a ][ b ];
else if (b>i) subA[a-1][b-1] = A[ a ][ b ];
}
}
var sign = (i%2==0) ? 1 : -1;
detA += sign * A[0][i] * Determinant(subA);
}
return detA;
}
function generate()
{
var rowCount = document.getElementById('rowCount').value;
var colCount = document.getElementById('colCount').value;
var tbl = document.createElement('table');
tbl.insertRow(-1);
for (var j=0; j<=colCount; j++) tbl.tBodies[0].rows[0].insertCell(-1).innerHTML = j||' ';
for (var i=1; i<=rowCount; i++)
{
tbl.insertRow(-1).insertCell(-1).innerHTML = i;
for (var j=1; j<=colCount; j++)
{
var input = document.createElement('input');
input.id=input.name='m_'+i+'_'+j;
input.size = "5";
tbl.tBodies[0].rows[i].insertCell(-1).appendChild(input);
}
}
document.body.appendChild(tbl);
var det = document.createElement("INPUT");
document.body.insertBefore(det, tbl);
det.type = "button";
det.value = "Determinant";
det.onclick = function () {
var mtx = [];
for (var i = 1; i <= rowCount; i++) {
mtx[i - 1] = [];
for (var j = 1; j <= colCount; j++)
mtx[i - 1].push( tbl.rows[i].cells[j].getElementsByTagName("input")[0].value );
}
alert( Determinant( mtx ) );
};
}
</script>
rowCount: <input id='rowCount' type='text' value='4' /><br />
colCount: <input id='colCount' type='text' value='5' /><br />
<button onclick="generate()">generate</button>