Click to See Complete Forum and Search --> : Create a dinamic table


ph_Rodrigues
06-08-2006, 06:58 PM
Good night friends!
I'm trying to create a dinamic table.
The code that i'm using is:
<html>
<body>

<script language="JavaScript">
function tmp()
{
var newTable = document.createElement("table");
var newTr = document.createElement("tr");
var newTd = document.createElement("td");
newTd.innerHTML = "tmp";
newTr.appendChild( newTd );
newTable.appendChild( newTr );
document.body.appendChild( newTable );
}
</script>

<input type="button" onClick="tmp()" value="Click">

</body>
</html>
The problem is: when i click on 'Click' anyone action is happening... Somebody know what's happening??
Thanks for the attention! ;)

phpnovice
06-08-2006, 07:09 PM
function tmp()
{
var oTable = document.createElement("table");
var oTbody = document.createElement("tbody");
var oTr = document.createElement("tr");
var oTd = document.createElement("td");
oTd.appendChild( document.createTextNode( "tmp" );
oTr.appendChild( oTd );
oTbody.appendChild( oTr );
oTable.appendChild( oTbody );
document.body.appendChild( oTable );
}

ph_Rodrigues
06-08-2006, 07:18 PM
This code is result in this error:
'Expected object in line 21'

Line 21: '<input type="button" onClick="tmp()" value="Click">'

phpnovice
06-08-2006, 07:49 PM
Sorry, left a parenthesis off of this line:

oTd.appendChild( document.createTextNode( "tmp" ) );

ph_Rodrigues
06-08-2006, 07:55 PM
Ohhh... thanks!
Ok... sorry for my no-attention too.

phpnovice
06-08-2006, 08:02 PM
No problem.

Cheers.