Goodmorning, I have this piece of code on jquery to add the class "toHide" or "notHide" to a table.
$('#search').keyup(function () {
var inputString = $("#search").val();
$('td:first-child').parent().show();
$('td:first-child').parent().addClass("notHide");
$('td:first-child').parent().removeClass("toHide");
$var = $('td:first-child').parent('tr:not(:icontains(' + inputString + ')):not(:contains("Total"))');
$var.hide();
$var.addClass('toHide');
$var.removeClass('notHide')
});
I want this class to recalculate the last "Total"
I will post a image to context: Example
So, for example if I write something on search bar, the "Total: price" subtract the "toHide" price.
EDIT_0- I post my first question with PHP but maybe I can get some variable $total on jquery and substrat to that the with the tag toHide. And then update the total.
I have try with the access to the elements of the table but I dont understand at all the table.row[0]cells[0].innerText
EDIT_1: I have tried with this and I got it, but I need that all of that come from the selected ID tab:
$('#search').keyup(function () {
var x = [];
var y = [];
var $total = 0;
var inputString = $("#search").val();
$('td:first-child').parent().show();
$('td:first-child').parent().addClass("notHide");
$('td:first-child').parent().removeClass("toHide");
$var = $('td:first-child').parent('tr:not(:icontains(' + inputString + ')):not(:contains("Total"))');
$var.hide();
$var.addClass('toHide');
$var.removeClass('notHide')
var e = document.getElementById("labdb").value;
//var match = document.querySelector("#"+e);
//alert(match)
for (var price of document.querySelectorAll('tr.notHide td.price')) {
x.push(parseFloat(price.innerText));
}
for (var cantidad of document.querySelectorAll('tr.notHide td.quantity')) {
y.push(parseFloat(cantidad.innerText));
}
for(var i = 0; i <= x.length-1; i++){
$total += x[i] * y[i];
}
document.getElementById("total").innerText = $total;
});
I need that querySelectorAll comes from the item ID=e:
var e = document.getElementById("labdb").value;
var match = document.querySelector("#"+e);
Work, but need all of that comes from the ID of the selected tab(labdb.value)