0

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>
3
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by AleMonteiro
0

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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.