I want to count the input after it is filled with numbers, but if it is not filled then the input is not counted.
I tried using the following HTML
<input type="number" class="myclass" value="4">
<input type="number" class="myclass" value="2">
<input type="number" class="myclass" value="0"> <!-- "0" / blank, not counted -->
<input type="number" class="myclass" value="3">
<!-- count result = 3 -->
<div id="count"></div>
and javascript
function livecountinput(){
let num = document.getElementsByClassName('myclass').length;
let count = document.getElementById('count');
count.innerHTML = num
};
document.addEventListener("DOMContentLoaded", function(event) {
livecountinput();
});
all that works but if there are zeros still counted, how to solve it? Any help would be appreciated.
myclassshould beclassand nottype, correct? In javascript you are not accesing thevalueproperty of any input. I think you should consider that.