[help] Java Table

I am trying to loop a table in JavaScript. PLease help!

<html>
<head>
<body bgcolor="#000000" text="#FFFFFF">
<b>Number of columbs:</b><input type="text" name="col" value="Enter a Number"><br>
<b>Number of rows:</b><input type="text" name="row" value="Enter a Number"><br>
<input type=button value="Do the Table" name=button onClick=code.value>
<table border=2>
<script language="JavaScript">
alert(code)
var code=""
for (var i=1;i<='col.value';i++){
code += "<tr>";
for (var j=1;i<='row.value';j++){
 code += "<td>" +eval(5*(i-1)+1) + "</td>";
 }
 code += "</tr>";
}
code += "</table>"
document.write(code)
</script>
</body>
</head>
</html>

Thanx!

#156050

No one!?!?!?!?!?!?

::BUMP::

#157617

Hmn... what you're trying to do... you'd need to write the whole page in JavaScript with the document.write tags, and ask the user for the rows and columns on startup with popup input dialogs... I think that'd be the only way to do it with Javascript...

--edit--

This'll work, but only in IE (afiak) -- edited - will now also give you the source code for the table in the large textarea.

<html>
<head>
<script language="JavaScript">

function gencode() {
var code = '<table border="2">\n';
var cols = theForm.colInput.value;
var rows = theForm.rowInput.value;

for (var i=1;i<=cols;i++) {
 code += "<tr>\n";
 for (var j=1;j<=rows;j++) {
  code += "<td>" + eval(5*(i-1)+1) + "</td>";
 }
 code += "\n</tr>";
}
code += "\n</table>\n";
tableArea.innerHTML = code;
theForm.sourceCode.value=code;
}
</script>

<body bgcolor="#000000" text="#FFFFFF">

<form id="theForm">
<b>Number of columns:</b>
<input type="text" id="colInput" value="Enter a Number"><br />
<b>Number of rows:</b>
<input type="text" id="rowInput" value="Enter a Number"><br />
<input type=button value="Do the Table" onClick="javascript:gencode()"><br />
<textarea id="sourceCode" rows="10" cols="60">Source Code will appear here</textarea>
</form>

<span id="tableArea">
</span>

</body>
</head>
</html>

#157629

*bump* because I got it working. Check edit of last post.

#157660

Originally posted by Cerebral@May 6 2004, 11:53 PM

*bump* because I got it working.  Check edit of last post.

;) that is not a lurk Cerebral ;) and it isnt sarcastic either, are we loosing our charm? :P

Glad to see you back bud.

#157716

Originally posted by Seph@May 6 2004, 03:42 PM

;) that is not a lurk Cerebral ;) and it isnt sarcastic either, are we loosing our charm? :P

Glad to see you back bud.

Oooo, I'm sooo lurky!

Now, either that's true, or sarcastic, so at least I'm 50% of what I used to be. :D

#157818