I want to update the Input field with a button and auto display of all Input fields above. If the button is pressed, the input will automatically add a number and if there is an addition, the total input must also be added automatically.
function eoscounting() {
var Eos = parseInt(document.getElementById('eos_count').value, 10);
Eos = isNaN(Eos) ? 0 : Eos;
Eos++;
document.getElementById('eos_count').value = Eos;
}
function basocounting() {
var Baso = parseInt(document.getElementById('baso_count').value, 10);
Baso = isNaN(Baso) ? 0 : Baso;
Baso++;
document.getElementById('baso_count').value = Baso;
}
function stabcounting() {
var Stab = parseInt(document.getElementById('stab_count').value, 10);
Stab = isNaN(Stab) ? 0 : Stab;
Stab++;
document.getElementById('stab_count').value = Stab;
}
function segcounting() {
var Seg = parseInt(document.getElementById('seg_count').value, 10);
Seg = isNaN(Seg) ? 0 : Seg;
Seg++;
document.getElementById('seg_count').value = Seg;
}
function monocounting() {
var Mono = parseInt(document.getElementById('mono_count').value, 10);
Mono = isNaN(Mono) ? 0 : Mono;
Mono++;
document.getElementById('mono_count').value = Mono;
}
function limcounting() {
var Lim = parseInt(document.getElementById('lim_count').value, 10);
Lim = isNaN(Lim) ? 0 : Lim;
Lim++;
document.getElementById('lim_count').value = Lim;
}
function findTotal() {
const fees = document.querySelectorAll(".fee");
const total = document.querySelector("#total");
let sum = 0;
fees.forEach(fee => {
if (fee.valueAsNumber) {
sum += fee.valueAsNumber;
}
});
total.value = sum;
}
<input type="number" id="eos_count" class="fee" name="qty" onchange="findTotal()" />
<input type="number" id="baso_count" class="fee" name="qty" onchange="findTotal()" />
<input type="number" id="stab_count" class="fee" name="qty" onchange="findTotal()" />
<input type="number" id="seg_count" class="fee" name="qty" onchange="findTotal()" />
<input type="number" id="mono_count" class="fee" name="qty" onchange="findTotal()" />
<input type="number" id="lim_count" class="fee" name="qty" onchange="findTotal()" />
<br /><br />
<input type="number" name="total" id="total" />
<br /><br />
<button class="input" value="myvalue" onclick="eoscounting()">Eosinofil</button>
<button class="input" value="myvalue" onclick="basocounting()">Basofil</button>
<button class="input" value="myvalue" onclick="stabcounting()">Netrofil Batang</button>
<button class="input" value="myvalue" onclick="segcounting()">Netrofil Segmen</button>
<button class="input" value="myvalue" onclick="monocounting()">Monosit</button>
<button class="input" value="myvalue" onclick="limcounting()">Limfosit</button>
Any help would be appreciated.
findTotal()at the end of all thexxxcounting()functions.function counting(what) { var val = parseInt(document.getElementById(what).value, 10); val = isNaN(val) ? 0 : val; val++; document.getElementById(what).value = val; }. I just copied your function and hope that I didnt introduce a typo :)