Answer the question
In order to leave comments, you need to log in
How to make a script enter a number in input?
I'm writing a userscript to automatically fill in a dozen input fields with a number.
Usually such a question was solved through "document.querySelector('input').value = number", but not now. Visually, the text changes and value but the old value is sent (or as if I didn’t enter anything)
.
There is an input field:
input type="number" class="form-control input-number-no-arrows text-center" rv-currency-value="value"
Yes
let lomar = 45;
Task:
Implement the script so that the "lomar" number is automatically placed in the input.
Answer the question
In order to leave comments, you need to log in
After the input, the appropriate events need to be fired so that the scripts on the page can understand that the value has changed. Try like this:
document.querySelector('input').value = 'значение';
document.querySelector('input').dispatchEvent(new Event('keyup'));
document.querySelector('input').dispatchEvent(new Event('input'));
document.querySelector('input').dispatchEvent(new Event('change'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question