I want to display array values in my table rows which I am getting from input values. I create a getting a array but doesn't get idea how can I display them in table?
I want to add more values in same array when I am adding it also I want to delete table row by clicking on delete at same time its need to be delete from array this is my code
var users = [
[1, "Yuvraj"],
[2, "Shweta"],
[3, "Namita"],
[4, "Tanvi"]
]
$(document).ready(loadTable);
function loadTable() {
for (var i = 0; i < users.length; i++) {
for (var j = 0; j < users[i].length; j++) {
console.log(users[i][j])
}
}
}
$("#submit").on('click', function() {
var temp = [document.getElementById("id").value, document.getElementById("name").value]
users.push(temp)
loadTable();
});
<html><head><title>Hello</title>table,
th,
td {
border: 1px solid black;
}
<html>
<head>
<title>Hello</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<input type="text" name="id" id="id">
<input type="text" name="name" id="name">
<button type="button" id="submit">Add</button>
<table id="demo">
<tbody>
</tbody>
</table>
</body>
</html>
<html>
<head>
<title>Hello</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<input type="text" name="id" id="id">
<input type="text" name="name" id="name">
<button type="button" id="submit">Add</button>
<table id="demo">
<tbody>
</tbody>
</table>
</body>
</html>
<script>
var users = [[1, "Yuvraj"], [2, "Shweta"], [3, "Namita"], [4,"Tanvi"]]
$(document).ready(loadTable);
function loadTable() {
for(var i = 0; i < users.length; i++){
for(var j = 0; j < users[i].length; j++){
console.log(users[i][j])
}
}
}
$("#submit").on('click', function() {
var temp = [document.getElementById("id").value, document.getElementById("name").value]
users.push(temp)
loadTable();
});
</script>
<style>
table, th, td {
border: 1px solid black;
}
</style>