Skip to content

Instantly share code, notes, and snippets.

@Lvcios
Last active September 20, 2019 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lvcios/477ebcb80cc2c7be5ab630caad55e862 to your computer and use it in GitHub Desktop.
Save Lvcios/477ebcb80cc2c7be5ab630caad55e862 to your computer and use it in GitHub Desktop.
Ejemplo multiplicación dinámica
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<table id="tablaFrus">
<thead>
<tr>
<th>Peso</th>
<th>Piezas</th>
<th>Total</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>
//la llamada ajax retorna un objeto similar:
var arr = [
{ part_number:1, fru_weiIght : 1.82 },
{ part_number:2, fru_weiIght : 2.82 },
{ part_number:3, fru_weiIght : 4.82 },
{ part_number:4, fru_weiIght : 3.82 },
]
arr.forEach(function(item, index){
var str = "<tr>";
str += "<td>" + item.fru_weiIght +"</td>"
str += "<td><input class='inputable' data-part_number='" + item.part_number +"' data-fru_weiIght='" + item.fru_weiIght + "'/></td>"
str += "<td><label data-part_number='" + item.part_number +"'>Resultado</label></td>"
str += "</tr>"
$("#tablaFrus").find("tbody").append(str)
})
$( ".inputable" ).on( "change", function() {
var peso = $(this).attr("data-fru_weiIght");
var part = $(this).attr("data-part_number");
var resultado = $(this).val() * peso;
$("label[data-part_number = '" + part +"']").text(resultado)
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment