简体   繁体   中英

Issues setting a value to a select box on the onload

I'm having issues setting a value to a select box when loading the page. On the onload I parse the URL for variables and after that I have to set the values retrieved from the url to a specific select box. The problem is when I'm trying to set the value using dijit:

dijit.byId("assettypeselect").set('value',queryObject.assettypeselect);

an error occurs because dijit library is not loaded yet. I've used dojo.addOnLoad and dojo.ready, but none of those work. Is there another eventhandler I can use that waits until all libraries are loaded or in what other way can I work to solve this.

Thanks for your time!

A likely solution, based off the limited information you've provided, is to wait for the window 's load event to fire. If dijit is still undefined have a look in your console and check to make sure the external/internal library is being requested properly. Also, if dijit is being loaded AMD style, make sure you've referenced it as a dependency .

window.addEventListener('load', function(){
    dijit.byId("assettypeselect").set('value',queryObject.assettypeselect);
}, false);

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload#Notes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM