I am working with the datatable, where data filled from api service.
I am adding checkboxes to eash row in action column.
When i click checkbox is checked, the value of that specific record passed to javascript function using 'onchange' event.
Same with the uncheck function.
Sample Script
//checkbox added to each row holding unique id(ignored mentioning variables)
var passingId,orgName;
var dataList=[];
<td><input type="checkbox" id=passingId onchange="checkThis(passingId + ',' + orgName )"/></td>
function checkThis(ids, oName) {
var el = document.getElementById(ids);
if (el.checked) {
$.post("demo_test_post.asp",
{
OId: ids,
ONAme: oName
});
var listItemAdd = oName;
dataList.push(listItemAdd);
alert(dataList);
}
else if (!el.checked) {
$.post("demo_test_post.asp",
{
OId: ids,
ONAme: oName
});
var listItemRemove = oName;
dataList.pop(listItemRemove);
alert(dataList);
}
}
This method push data to array when any record is check.
When unchecked, the record of that row(oName only in this case) must be removed from array.
Adding part has no problem, removing part is working but not removing selected value but removes last stored value. I am surely missing something, as i am new to javascript can't understand the examples.
If someone can help, please do help.Thanks for your time.