Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
How to execute a series of dispatchevents in javascript and wait after each one is completed

I'm writing a chrome extension where I need to simulate user clicks on a webpage before pasting information into fields. The page has a listbox with onchange javascript (not mine) attached to it. Depending on the selection of the listbox the page shows different kind of information. So basically I want to execute a series of dispatchEvents.

The issue I have is that I need to wait until the onchange javascript on the listbox is done with it's thing before moving on to the next dispatchEvent in order to refer to new elements created by the onchange javascript. How do I do that?

If I just do one call like this:

elmt = document.getElementById('freightServiceSelect');
elmt.selectedIndex = 24;
elmt.dispatchEvent(new Event("change"));

it works fine. But if I then add the next call immediately after, like this:

elmt = document.getElementsByName("freightServiceAddon")[0];
elmt.checked = true;
elmt.dispatchEvent(new Event("click"));

it gets executed immediately and the element "freightServiceAddon" is at that point undefined.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!