1
I’m in trouble, I don’t have much experience with Javascript and jQuery and need to do the following.
I have a table, each row is a product and has a value.
I need to add a percentage to this value according to the value of a slider.
So for example, if the cost of a product is 0.10, if I move the slider to 10, add 10% to this value and update the same.
The problem is that with the code below I’m not getting to do for every line.
I’ve tried everything, but the most I got is where you got the first line, but add this value on all lines.
I needed a way to move the slider and just modify the p tag of that line and not the others.
also need to have this function on all lines (currently only working on the first).
I am using a Javascript function to add the items in the table, code below.
Most likely a simple solution, I count on the support of experts.
/* myRange - Slider ID
prod - table id;
.teste - classe a tag p onde tem o preço.
*/
//slider
$('#prod').on('click', '#myRange', function () {
var slider = document.getElementById('myRange');
slider.oninput = function() {
$('.teste').closest("p").html(slider.value);
console.log(slider.value);
//output.innerHTML = slider.value;
}
} );
// Listar todos os produtos
$("#add-all").click(function() {
// Listar todos os itens.
for (i = 0; i < Items.length; i++) {
var id = Items[i].id;
var nome = Items[i].Nome;
var descri = Items[i].Descricao;
var emb = Items[i].Embalagem;
var lab = Items[i].Laboratorio;
var gen = Items[i].Generico;
var rsm = Items[i].RSM;
var rsmnew = rsm.slice(0, 9);
var val = Items[i].Vunit;
var valF = "TBD";
var markup = "<tr><td>" + nome + "</td>" +
"<td>" + descri + "</td>" +
"<td>" + emb + "</td>" +
"<td>" + lab + "</td>" +
"<td>" + gen + "</td>" +
"<td><a target='_blank' href='http://www.smerp.com.br/anvisa/?ac=out&anvisaId=" + rsmnew + "'>" + rsm + "</a></td>" +
"<td><p class='custo' id='" + id + "'>" + val + "</p><a class='editar' data-toggle='modal' data-nome='" + nome + "' data-id='" + id + "' data-descri='" + descri + "' data-target='#changePrice'><i class='fas fa-edit iconeE' title='Editar'></i></a></td>" +
"<td><p class='teste'>" + valF + "</p><a class='remover'><i class='fas fa-minus-circle icone' title='Ocultar'></i></a><br><input style='width:70px;' type='range' id='myRange' min='-20' max='60' value='0' class='custom-range'></td>'";
var markup1 = "<tr><td>" + nome + "</td>" +
"<td>" + descri + "</td>" +
"<td>" + emb + "</td>" +
"<td>" + lab + "</td>" +
"<td>" + gen + "</td>" +
"<td><a target='_blank' href='http://www.smerp.com.br/anvisa/?ac=out&anvisaId=" + rsmnew + "'>" + rsm + "</a></td>" +
"<td>" + val + "</td>" +
"<td><p class='teste'>" + valF + "</p><a class='remover'><i class='fas fa-minus-circle icone' title='Ocultar'></i></a><br><input style='width:70px;' type='range' id='myRange' min='-20' max='60' value='0' class='custom-range'></td>'";
if ($("#userType").attr("value") == "user") {
$("table tbody").append(markup1);
}
if ($("#userType").attr("value") == "adm") {
$("table tbody").append(markup);
}
}
});
Welcome to Stack Overflow in English. Please click on edit and translate the question.
– Luiz Augusto
Guy puts at least HTML ai tb, will help you answer. If the html structure makes things a little difficult
– hugocsl
Could put html code.
– Maury Developer
Error is class. You are changing all of them,recommendation is to use id. Or use which index it is.
– Maury Developer
This solved a problem for me. Now it’s only working for the first line, ideas of how I can make it work on all lines?
– Jeferson Costa