Hi i am facing error in below code not able to add rows could anyone help please

<html>
<head>
<title>Row Added</title>
</head>
<script>
function sample(){
var table='<table width="100" id="+sample+">';
table=table.concat("<tr>");
table=table.concat("<td>Add rows</td>");
table=table.concat("<td><input type="button" name="Add" value="Add"</td>");
table=table.concat("<td><input type="button" name="Delete" value="Delete"</td>");
table=table.concat("</tr>");
table=table.concat("</table>");
document.getElementById("sample").innerHTML+=table;
}
</script>
<body>
<table>
<tr>
<td>Enter the rows</td>
<td><input type="button" name="Submit" value="Submit" onclick="sample"</td>
</tr>
</table>

</body>
</html>

Recommended Answers

All 2 Replies

Hi there are formating issues in your code and document.getElementById doesnt exist in you code!

    <html>
    <head>
    <title>Row Added</title>
    </head>
    <script>
    function sample(){
    var table='<table width="100" id="'+sample+'">';
    table=table.concat('<tr>');
    table=table.concat('<td>Add rows</td>');
    table=table.concat('<td><input type="button" name="Add" value="Add"></td>');
    table=table.concat('<td><input type="button" name="Delete" value="Delete"></td>');
    table=table.concat('</tr>');
    table=table.concat('</table>');
    document.getElementById("someid").innerHTML+=table;
    }
    </script>
    <body>
    <table>
    <tr>
    <td>Enter the rows</td>
    <td><input type="button" name="Submit" value="Submit" onclick="sample()" /></td>
    </tr>
<tr>
<td id='someid'></td>
</tr>
    </table>
    </body>
    </html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.