I'm using a Javascript bookmarklet to automatically fill out a form on a page. Some of the options given are drop down selections, which reveal different options depending on what is selected using onchange(). I have code similar to this:
/* Gets first drop down and sets value to first in list */
var dropDown1 = document.getElementById("dropDown1Name");
dropDown1.value = "option1InDropDown";
dropDown1.onchange();
/* Sets value of second drop down to option that is available when first option in first drop down is selected */
var dropDown2 = document.getElementById("dropDown2Name");
dropDown2.value = "optionRevealedByDropDown1Change";
However this doesn't work because the onchange() doesn't populate the second drop down by the time I set it to the value. By the time the script finishes executing, there is no value set in dropDown2. I've tried several methods to make the code "wait" but I haven't been able to find a correct solution. Any suggestions are appreciated.