Hello there,

I've found some examples on the web on how to load an external javascript file dynamically, but I'm running into some problems. Here's what I want to do:
  1. The user clicks on a particular element which loads an external javascript file dynamically. The javascript contains a function.
  2. Then, the onclick attribute calls the function that was loaded.
The problem I'm having is that I can get the javascript to load, but when the function is called, it doesn't exist yet. If I click on the element again, it does. However, I need it to work the first time.

My goal is to be able to dynamically load javascript for my AJAX application, so I don't have to load everything right away, so it's more of an "as-needed" thing.

Has anyone succesfully accomplished this?