How to simulate manual input in input js?

  • 0
    I have a google extension and I need to enter & lt; input type = "text" id = "my" class = "name" & gt; value on the site. I tried through document.getElementById ('# my'). Value = but the form didn't submit. I think simulating manual input will save the day.
    JavaScript August Hickman, Jan 17, 2019

  • 2 Answers
  • 0
    Try this:

    input = document.querySelector('#my');
    input.value = 'Вставляемый текст';
    input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true }));
    input.dispatchEvent(new KeyboardEvent('keypress', { bubbles: true }));
    input.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true }));
    input.dispatchEvent(new Event('input', { bubbles: true }));
    input.dispatchEvent(new Event('change', { bubbles: true }));
    Leah Velez

  • 0
    try it just like this

    <input type="text" id="my" class="name" value="ваше значение">
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!