locked
JavaScript & OnLoad RRS feed

  • Question

  • I have a form in CRM 2011 for which there are are two libraries defined. The first library has some code outside functions that initializes some values. The OnLoad event calls a function in the second library and that function depends on the values mentioned above. What I experience is that some but not all of the values get initialized and then the OnLoad event function is being called. It seems like the OnLoad function is interrupting the initialization of the values.

    That leads me to the question how the libraries are loaded. Can the loading be interrupted by the OnLoad function? Also can I expect that library 1 will load completely including execution of code outside functions before library 2 is being loaded? From my experience it is not the case but I try to understand how this really works.

    Monday, April 2, 2012 6:46 AM

Answers

  • What should happen is the following.

    If you have two libraries referenced in the form. CRM will add these libraries to the form as script references in the order as defined. Then it is the browsers responsibility to load and execute these in the correct order. Only after all libraries and other resources have been completed the onload event will be executed. I have not experienced any problems with this.

    Based on what you are describing your libraries should load correctly. You can try using the IE Developers tools (Press F12) this will allow you to set break points in the javascript and allow you to track what is happing. First load the form, press F12, start the script debugger, set break points then reload the form again (F5). This way you can see in what order things happen and also what the exact values your variables have.


    Patrick Verbeeten
    www.patrickverbeeten.com
    www.wavextend.com

    • Proposed as answer by The Hosk Monday, April 2, 2012 8:53 AM
    • Marked as answer by hfaun Monday, April 2, 2012 3:45 PM
    Monday, April 2, 2012 8:38 AM

All replies

  • What should happen is the following.

    If you have two libraries referenced in the form. CRM will add these libraries to the form as script references in the order as defined. Then it is the browsers responsibility to load and execute these in the correct order. Only after all libraries and other resources have been completed the onload event will be executed. I have not experienced any problems with this.

    Based on what you are describing your libraries should load correctly. You can try using the IE Developers tools (Press F12) this will allow you to set break points in the javascript and allow you to track what is happing. First load the form, press F12, start the script debugger, set break points then reload the form again (F5). This way you can see in what order things happen and also what the exact values your variables have.


    Patrick Verbeeten
    www.patrickverbeeten.com
    www.wavextend.com

    • Proposed as answer by The Hosk Monday, April 2, 2012 8:53 AM
    • Marked as answer by hfaun Monday, April 2, 2012 3:45 PM
    Monday, April 2, 2012 8:38 AM
  • Patrick, I found a bug based on your input (F12). I have a feeling that this bug did somehow interfere with the code following the error and that this was the reason why the OnLoad seemed to happen before all the javascript code was executed.
    Monday, April 2, 2012 3:48 PM