N
N
Nikita Kozlov2020-04-13 20:01:48
JavaScript
Nikita Kozlov, 2020-04-13 20:01:48

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

1 answer(s)
N
Nadim Zakirov, 2020-04-13
@Bunig

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'));

If it doesn't help, look in the console for which handlers hang on the desired field and manually call them after changing the value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question