embed HTML using javascript
Hi,
I'm trying to load a js file and a textbox into an HTML file. I'm using the following code.
Code:
document.getElementById("yyyy").innerHTML = '<script type="text/javascript" src="http://yyyyy.js"></script> <input type="text" name="yyyyBox" onKeyUp="convert()">';
The textbox is loaded successfully, however the js file is not loaded, i'm not able to call a function that is inside the js file.
Error msg
Code:
test.html:1 Uncaught ReferenceError: convert is not defined
I was wondering if there is a way to get this working.
Thanks
Re: embed HTML using javascript
I use JS/jQuery to load both HTML and "new JS functions" - AJAX call to get the TEXT (sometimes in a file on the server and sometimes from a table in a database).
If the "text" is a function I use EVAL() to load it into the DOM.
Code:
function compileFormula(intGO) {
eval("g_objGrid[intGO].formula = function(currentRow,currentCell,item) {"
+ g_objGrid[intGO].formulaSource + "\n}");
}
If the "text" is HTML I use jQuery to load it into the DOM.
Code:
strEP = g_editpanels[strFromTo] || "";
if (strEP.length == 0) {
strEP = "<br /><span>Edit Panel not found, please try to log in again.</span>";
}
$(strEP).css("display", "none").appendTo(strEditPanel).addClass("acs-edit-bottom")
.removeAttr("id").attr("id", strNewId);
wesEP = $("#" + strNewId);
Re: embed HTML using javascript