Hi,
I need to write a javascript function dynamically. This function does not get called at any stage, it simply must exist (at a certain place) on the page. I have tried two methods as you see below. (For testing purposes I have simplified the code, and set a button to call the function that will not get called).
Here is the second try:
Neither of these options work, however the first one seems to have more success (it is at least written, even if I can't call the function)
Thank you for your time.
Regards,
Keyper
The Key is more powerful than the Sword.
I need to write a javascript function dynamically. This function does not get called at any stage, it simply must exist (at a certain place) on the page. I have tried two methods as you see below. (For testing purposes I have simplified the code, and set a button to call the function that will not get called).
Code:
<script language="JavaScript" type="text/JavaScript">
function myfunction()
{
var code='Hello JS';
code+="\n";
code+='<script language="JavaScript" type="text/JavaScript">';
code+="\n";
code+=' function myalert() { alert(\'stuff\'); } ';
code+="\n";
code+='<\/script>';
document.getElementById('insert_53').innerHTML=code;
alert(code);
}
</script>
<button onClick="myfunction()" id="test1">One</button>
<br>
<div id="insert_53"></div>
<br>
<button onClick="myalert()" id="test2">Two</button>
Here is the second try:
Code:
<script language="JavaScript" type="text/JavaScript">
function myfunction()
{
thefunctionobj=function(){function myalert() { alert('stuff'); }};
document.getElementById('insert_53').appendChild(thefunctionobj);
}
</script>
<button onClick="myfunction()" id="test1">One</button>
<br>
<div id="insert_53"></div>
<br>
<button onClick="myalert()" id="test2">Two</button>
Neither of these options work, however the first one seems to have more success (it is at least written, even if I can't call the function)
Thank you for your time.
Regards,
Keyper
The Key is more powerful than the Sword.