+4  A: 

You can try adding an event handler for the scripts onload and continuing your code from there.

e.g.

function inc(fname, callback)
{
    var body = document.getElementsByTagName('body').item(0);
    script = document.createElement('script');
    script.src = filename;
    script.type = 'text/javascript';
    script.onload = callback;
    body.appendChild(script);
}

function CheckCaptcha()
{
    var CaptchaWord="";

    CaptchaWord = document.getElementById('studentusername').value;
        inc("md5.js", function() {
        //Add MD5 function here.
        });

}

The alternative to this approach (which will work far more rebustly as well) is to include the md5 script directly as opposed to using the inc function.

<script src="/path/to/md5.js" type="text/javascript"></script>
<script type="text/javascript">
function CheckCaptcha()
{
    var CaptchaWord="";
    CaptchaWord = document.getElementById('studentusername').value;
    return md5(CaptchaWord); //or something
}
</script>
barkmadley
Actually, I want the MD5 of "CaptchaWord" to be returned in a new variable.
RPK
if that is the case, then you will want to include the javascript directly in the page (preferably above the script that uses it) as opposed to asynchronously including it using the inc function.
barkmadley
+2  A: 

As onload doesnt work in ie you need to add onreadystatechange.

function inc(fname, callback)
{
    var body = document.getElementsByTagName('body').item(0);
    script = document.createElement('script');
    script.src = filename;
    script.type = 'text/javascript';
    script.onload = callback;
    script.onreadystatechange= function () {
      if (this.readyState == 'complete') callback();
    }

    body.appendChild(script);
}

function CheckCaptcha()
{
    var CaptchaWord="";

    CaptchaWord = document.getElementById('studentusername').value;
        inc("md5.js", function() {
        //Add MD5 function here.
        });

}
eskimoblood