Forum Discussion
How to Clear or Reset Numeric entry field?
Hello
I have a slide with numeric entry variables on - when the user returns to the slide, I want it to reset but if I set the variable to 0 when the slide starts, a 0 appears in the box rather than it saying 'enter number here'. Is there a way to set the variable back to blank rather than 0?
Hello Neha,
Happy to help!
There isn't a way to reset the numerical input box after a value has been assigned to it without manually going into the input box and pressing backspace, but some members of the community shared this Javascript solution which seems to have some positive feedback in the forums.
I'll let other members chime in so they can share alternative solutions that might help!
- NedimCommunity Member
The numerical field is designed to only accept numeric values. If the value of a numeric field is set to an empty string " ", it is being interpreted as 0 as a way for the numerical field to provide a valid numeric value. If you look in the SL code you may notice that even a numeric field is the text type attribute that actually returns a string. If you are not about to do some number calculations I suggest using the text entry field instead and set its initial value to "Enter number here". Try and test this code on a single text entry field:
let numField = document.querySelector('.acc-textinput')
numField.addEventListener('input', function () {
// Get the current value of the input field
let inpVal = numField.value;
// Remove any non-numeric characters
inpVal = inpVal.replace(/[^0-9]/g, '');
// Update the input field value with the cleaned value
numField.value = inpVal;
});