I have a situation where I want to focus on an input field when the user presses the '/' key. The issue is that once the element is focused, it automatically adds the '/' key to the input field because of how the detection is set up.
document.addEventListener("keypress", function(event) {
var element = document.getElementById("formInput")
if (event.key == '/') {
element.focus()
element.value = element.value.slice(0, -1)
}
})
I attempted to slice the value after focusing but found that the input field's value does not update until the function from the event listener finishes executing.
Is there a way to remove the extra '/' from the input field after it appears in the input field?