JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<input type="text" name="selite[]" value="Pulla"><input type="text" name="maara[]" size="4" value="2"><input type="text" name="kplhinta[]" size="4" value="2"><input type="text" name="alvpros[]" size="4" value="23"><input type="text" name="verollinen[]" value="" size="4" disabled="disabled">
</div>
<div>
<input type="text" name="selite[]" value="Kahvi"><input type="text" name="maara[]" size="4" value="3"><input type="text" name="kplhinta[]" size="4" value="1"><input type="text" name="alvpros[]" size="4" value="23"><input type="text" name="verollinen[]" value="" size="4" disabled="disabled">
</div>
<div>
<input type="text" name="selite[]" value="Vodka"><input type="text" name="maara[]" size="4" value="1"><input type="text" name="kplhinta[]" size="4" value="5"><input type="text" name="alvpros[]" size="4" value="23"><input type="text" name="verollinen[]" value="" size="4" disabled="disabled">
</div>
JavaScript
$('input[name="maara[]"], input[name="kplhinta[]"], input[name="alvpros[]"]').keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
if (key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
console.log('Sallittu merkki');
}
else {
e.preventDefault();
console.log('Eipäs sallita ihan kaikkea...');
}
});
$('input[name="maara[]"], input[name="kplhinta[]"], input[name="alvpros[]"]').keyup(function(e) {
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
if (key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
console.log('Päivitetään rivi...');
paivitaRivi($(this).parent());
}
});
$('div').each(function() {
console.log('Sivun latauksen yhteydessä laskettavat hinnat');
paivitaRivi($(this));
console.log('Hinnat laskettu');
});
function paivitaRivi(rivi) {
maara = parseInt(rivi.find('input[name="maara[]"]').val());
kplhinta = parseInt(rivi.find('input[name="kplhinta[]"]').val());
alvpros = parseInt(rivi.find('input[name="alvpros[]"]').val());
tuote = rivi.find('input[name="selite[]"]').val()
hinta = (100 + alvpros) * (maara * kplhinta) / 100;
console.log("Tuotetta '"+ tuote +"' yhteensä "+ maara +" kappaletta, a-hintaan: "+ kplhinta +' ja veroprosentilla: '+ alvpros);
console.log('Päivitä tuotteen '+ tuote +', hinnaksi: '+ hinta);
rivi.find('input[name="verollinen[]"]').val(hinta);
}