I'm trying to create a javascript function on-the-fly. It loads OK but errors when the button is clicked (dreaded object required). I suspect it's a bit of an old chestnut but if you could help there's a case of ketchup in the post.
Code:
<html>
<head>
<script language = "JavaScript" type="text/javascript">
function onload() {
var jselem = document.createElement("div");
jselem.innerHTML = "<script language = 'JavaScript' type='text/javascript'>function xx(){alert('jkjk');}<\/script>";
document.getElementById("jsdiv").appendChild(jselem);
}
</script>
</head>
<body onload='onload()'>
<input type=button onclick='xx()'>
<div id="jsdiv"></div>
</body>
</html>