I have a small project with some fields that can insert and delete array objects. I have a problem on removing the selected row (using a checkbox) from my Array Object. Remove function works but does not remove the object in my array.
below is my html.
<div class="container">
<input id="list-input" />
<select id="select-status">
<option value="on-going">on-going</option>
<option value="completed">completed</option>
</select>
<button id="add">Add To List</button>
<button id="delete">Remove From List</button>
</div>
<div class="container">
<h1>Your List</h1>
<div id="mylist">
<table id="mylist">
<thead>
<th>ID Number</th>
<th>Description</th>
<th>Status</th>
</thead>
<tbody>
</tbody>
</table>
</div>
<button id="clear">clear</button>
</div>
and my js for my add and remove function
var tasks = [];
var count = 0;
$('document').ready(function(){
$('#add').click(function() {
var desc = $.trim($('#list-input').val());
var status = $('#select-status').val();
var id = Date.now();
item = {};
if (!desc) {
item.id = "";
alert("Input a description");
return;
}
//clear input field
$('#list-input').val('');
$('#list-input').focus();
item.id = id;
item.description = desc;
item.status = status;
tasks.push(item);
var row = "<tr>";
row += "<td id="+ item.id +">" + item.id + "</td>";
row += "<td>" + item.description + "</td>";
row += "<td>" + item.status + "</td>";
if(item.status === "completed"){
row += "<td><input type='checkbox' name="+ item.id +"/></td>";
}
else{
row += "<td><input type='checkbox' name="+ item.id +"/></td>";
}
$("#mylist tbody").append(row);
});
$('#delete').on('click', function() {
if(confirm("Are you sure to delete selected list?")){
$('#mylist input:checked').closest('tbody tr').remove();
}
else{
return;
}
});
});at the end of your code.