Click to See Complete Forum and Search --> : Write a Table Cell One by One...


ChikoritaPro
01-08-2003, 07:31 PM
Here's something I have been wondering about. I was helping someone to make a prompt quiz, but a problem has occured. My friend wants to write a cell one by one in the same row when a prompt is answered. Instead, the entire table is only written after the </table> tag has been played. Here is an example of what I'm talking about:


<script language="JavaScript">
<!--
// Note this is just an example.
// To see this for yourself, feel free to download the file.
document.write("<table border=1 cellspacing=0>")
for(x=1;x<=5;x++)
{
document.write("<td>Tada!</td>")
alert("This message slows the for() loop. Box number "+x)
// The alert() box is there to stall the for() loop each time.
// This should write "Tada!" every time the for() loop
// has repeated. Instead, it does not show until the end.
// No new rows are created.
}
document.write("</table>")
// At this point the table has finally been written.
// It does not write it each time.
//-->
</script>


Try the Script for yourself if you want to see what I mean. Instead of writing "Tada!" every time the for() loop completes one round, it waits until the final "</table>" tag has been written. Is there a way to actually allow yourself to write a cell one at a time in the same row, without creating a new table (that just makes it go to the next line)? It may be challenging to solve, it may be not. It's something that is wanted to know :rolleyes: .

AdamBrill
01-08-2003, 07:52 PM
Try this:

<html>
<head>
<title>Place a cell one at a time!</title>
<script language="JavaScript">
<!--
// Note this is just an example.
//document.write("<div>")
for(x=1;x<=5;x++)
{
document.write("<div style=\"position:relative; border:1px solid black; top:-"+x+"; width:100px;\">Tada!</div>")
alert("This message slows the for() loop. Box number "+x)
// The alert() box is there to stall the for() loop each time.
// This should write "Tada!" every time the for() loop
// has repeated. Instead, it does not show until the end.
// No new rows are created.
}

document.write("</div>")
// At this point the table has finally been written.
// It does not write it each time.
//-->
</script>
</head>
<body>
</body>
</html>

It uses <div> tags instead, but it should work just as well. Let me know if you have any more problems...