Hi!
I am attempting to change the innerHTML code of a div and to run javascript code at that time. But I seem to be unable to do it. The actual workings of the whole thing are really convoluted but here is the general idea:
<html>
<head><title>JavaScript test</title>
<script type="text/javascript">
function changeit(iVar)
{
var newinnerHTML = "";
if (iVar == 1)
{
newinnerHTML = '<script language="JavaScript"> alert("test");</script>';
}
else
{
newinnerHTML = "<a id='imagelink' name='imagelink' class='imagelink' target=_blank
href='home.html'>Home</a>";
}
document.getElementById('div1').innerHTML = newinnerHTML;
}
</script>
</head>
<body>
<body>
<div id="div1">
</div>
<form action="">
<input type="button" onClick="changeit(1);" value="change javascript" />
</form>
</body>
</html>
The end result is that I want to either show an image or play a .flv file depending upon the value of a variable. And it's all dynamic with the values coming from the database. (which is why it's too convoluted to post here)
So in a nutshell: I want to change the javascript on a page using javascript and have it run.
Any help would be greatly appreciated!
-Karin