0

I'm trying to programatically trigger the onchange event of an input that has the source below :

<input class="_2hvTZ pexuQ zyHYP" id="f1d5fcd30110a5c" aria-label="Phone number, username, or email" aria-required="true" autocapitalize="off" autocorrect="off" maxlength="75" name="username" type="text" value="">

I can see on devtools this input has a change listener attached, as you can see on the image at the end of the question. What i'm trying to do is call this event programatically, using the code below :

document.getElementById('f1d5fcd30110a5c').onchange();

But i get the error :

VM834:1 Uncaught TypeError: document.getElementById(...).onchange is not a function

How can i trig the attached event listener programatically using JS ?

enter image description here

Maheer Ali
  • 35,834
  • 5
  • 42
  • 73
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events – Bergi Feb 17 '19 at 13:43
  • 1
    @delphirules If the event handler you are trying to call was added using `addEventListener` the `onchange` property would be `null`. So you need to dispatch the event. The linked question describes how to. – Yury Tarabanko Feb 17 '19 at 13:45
  • @YuryTarabanko Thank you , i see the element.dispatchEvent method; do you know how do i send the change event passing parameters ? – delphirules Feb 17 '19 at 17:59

0 Answers0