I have a website with couple of dropdown lists. When a value is selected in one dropdown list, the site runs a javascript code that changes the options in other dropdown lists.
(Example: I select a country in the first list and the dropdown below it is populated with a list of cities from that country).
This isn't my website. I am trying to create a Greasemonkey script that will fill values to these dropdowns. I am able to simulate selection of an option using this jQuery command.
$('select[id="dropdown1"]').val("GBR").trigger('change');
This works fine. It selects the value in the top dropdown. Not in the others however, because they don't yet contain the values I am sending there.
I want the other dropdown lists to be populated according to my selection, but that doesn't happen until my script ends. In other words, the script that runs on the website and populates the dropdown lists waits for my script to end.
What I would like to achieve is to pause my script, allow website scripts to run and then continue my script. In other words, give website scripts priority to execute.
I tried using setTimeout but that didn't work. It even stop changing the top dropdown list value.
setTimeout(function() {
$('select[id="dropdown1"]').val("GBR").trigger('change');
}, 3000);
Any idea how to pause my script, let others to execute and then continue running my script?