I'm trying to create two number counters that can increment and decrement the other counter in real-time. Also I don't know Javascript too well.
<input type="number" step="1" value="10" name="counter1" id="counter1">
<input type="number" step="1" value="10" name="counter2" id="counter2">
If counter1 is increased, counter2 should be decreased, and vice versa; they are basically the inverse of each other. I've tried to implement some Javascript but it's not going well and I'm unsure of how to implement both incrementing and decrementing at the same time.
<script type="text/javascript"> //some non-working example code
function count() {
var counter1 = document.getElementById('counter1').value;
var counter2 = document.getElementById('counter2').value;
document.getElementById('counter2').onclick = function() { //onclick doesn't take into account if the input was increased or decreased.
counter2++;
counter1--;
}
document.getElementById('counter1').onclick = function() {
counter1++;
counter2--;
}
}
count();
</script>
onclickwith input.onChangeknow if the value was increased or decreased?