I am looking to implement a feature where users can input numbers that will be subtracted from a fixed total of 100. However, if the user deletes the input, I want the difference to be added back to the total of 100. Despite my attempts, the subtraction works fine but the addition does not when figures are deleted:
Here is the code snippet I have tried using HTML and JavaScript:
<input
type="number"
placeholder="Ex: 40"
v-model="e"
@keyup="validate()"
@blur="validate()"
required
/>
JS:
const total = ref(100);
const e = ref("");
const validate = (e) => {
if(e.value){
totalPercentages.value = total.value - e.value
}
};