How can add checkbox in input from enter?
<html>
<head>
</head>
<body>
Search: <input onkeyup="myFunction()" type="search" id="mySearch" value="">
<p>Click the button to display the value of the value attribute of the search field.</p>
<p id="demo"></p>
<table id="table">
<tr>
<td></td>
</tr>
</table>
<script>
function myFunction()
{
if(event.keyCode === 13){
debugger;
var table = document.getElementById("table");
var row = table.insertRow(-1);
var date = row.insertCell(0);
table.appendChild(row);
date.innerHTML = document.getElementById("mySearch").value;
//insert checkbox//
function editTd()
{
var rows = document.getElementById('table').rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
for(var j =0; j<row.cells.length; j++){
var inputs = document.createElement("input");
inputs.type = "checkbox";
rows.cells[j].appendChild(inputs);
};
};
};
editTd();
}
}
</script>
</body>
</html>
you just need to alter the line to this:
rows[i].cells[j].appendChild(inputs);
or possibly
rows[0].cells[j].appendChild(inputs);
<html>
<head>
</head>
<body>
Search: <input onkeyup="myFunction()" type="search" id="mySearch" value="">
<p>Click the button to display the value of the value attribute of the search field.</p>
<p id="demo"></p>
<table id="table">
<tr>
<td></td>
</tr>
</table>
<script>
function myFunction() {
if (event.keyCode === 13) {
debugger;
var table = document.getElementById("table");
var row = table.insertRow(-1);
var date = row.insertCell(0);
table.appendChild(row);
date.innerHTML = document.getElementById("mySearch").value;
//insert checkbox//
function editTd() {
var rows = document.getElementById('table').rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
for (var j = 0; j < row.cells.length; j++) {
var inputs = document.createElement("input");
inputs.type = "checkbox";
rows[i].cells[j].appendChild(inputs);
};
};
};
editTd();
}
}
</script>
</body>
</html>
it shows 2 checkbox's so if that is not what you wanted just need to change your loop logic. I hope this helps