Hey Reza:
After testing the loadjscssfile function you provided, this function works well.
You can try the following ways to figure out why it doesn't work on your form:
1. when you use relative path for the reference tag, make sure the file does exist under the same root.
For example: if you use <script src="/MARCH/MYExternal.js"></script>, the real src will be: http://YOUR-SERVICE/MARCH/MYExternal.js. If the file doesn't exist, an error 404 (not found) will occur.
Notice: In JavaScript, when you add <script> element with src attribute into <head>, the website will ALWAYS try to load the file.
(1). within the loadjscssfile function, if the src is invalid, this reference tag won't be added into <head>.
(2). if you still want to add the reference tag into <head> whether the src is valid or not, you can use the following function:
function directAddRefTag(filename, filetype){
if(filetype=='js')
$("head").append("<script type='text\/javascript' src='"+filename+"'><\/script>");
else if(filetype=='css')
$("head").append("<link rel='stylesheet' type='text\/css' href='"+filename+"'>");
}
After running this function, the reference tag will be added into <head> element as a child. If the src is invalid, the error 404 will occur. To avoid unnecessary error, we suggest you to always pass in a valid src.
2. make sure your file is under the same http or https with your server.
if your external JavaScript file is in http while your server is in https, the load request will be blocked.
3. I am not sure how you call this function.
(1). if you want to run the function when you first open the form, you can use the following code:
$(document).ready(function(){
loadjscssfile("MARCH\/MYExternal.js","js");
})
(2). If you want to call this function by clicking a button, you can use the following code:
$(document).ready(function(){
$('button').on('click', function(){
loadjscssfile("MARCH\/MYExternal.js","js");
});
})
You can also call this function by triggering other events.
Hope the above methods can solve your problem. Let me know if it works or not. :)