I have a form that allow user to enter a shift information (screenshot below).
I created an array to hold the value of the the table. The value is added into the array when user click 'Add'
$(function () {
var TechnicianItems = [];
$('#TechnicianAdd').click(function () {
var isValidItem = true;
if (isValidItem) {
var $technicianId = parseInt($('#TechnicianId').val().trim());
var $technicianText = $('#TechnicianId').children("option").filter(":selected").text().trim();
var $shiftId = parseInt($('#ShiftId').val().trim());
var $shiftText = $('#ShiftId').children("option").filter(":selected").text().trim();
var $duration = parseFloat($('#TechnicianDuration').val().trim());
var $break = parseFloat($('#TechnicianBreak').val().trim());
var $comment = $('#TechnicianComment').val().trim();
TechnicianItems.push({
TechnicianId: $technicianId,
ShiftId: $shiftId,
Duration: $duration,
Break: $break,
Comment: $comment
});
// Clear the fields after insert.
$('#TechnicianId').val('');
$('#ShiftId').val('');
$('#TechnicianDuration').val('');
$('#TechnicianBreak').val('');
$('#TechnicianComment').val('');
// Append the newly added entry to #partlogs table.
$table = $('#shiftlogs>tbody').last();
$row = $('<tr/>');
$row.append($('<td/>').html($technicianText));
$row.append($('<td/>').html($shiftText));
$row.append($('<td/>').html($duration));
$row.append($('<td/>').html($break));
$row.append($('<td/>').html($comment));
$row.append($('<td/>').html('<input type="button" class="remove" value="Remove" />'));
$table.append($row);
} //END if(isValidItem)
}); // END $('#TechnicianAdd').click()
});
How do I remove the item from the TehcnicianItems when 'Remove' button is clicked? I try to remove the row, but it doesn't work either.
$('.remove').click(function() {
$(this).closest('tr').remove();
})