Forum Moderators: open
I am filling a div with some data using ajax and would like to include some javascript within it. The response would look like this:
<script type="text/javascript">
<!--
function show() {
alert('OI-2!');
}
-->
</script>
<input type="button" onclick="alert('OI-1!');show();" value="Alert" />
It seems to fill the div fine and when the button is pushed the first alert works but not the second.
Any ideas?
Thanks,
Dave
For your script to execute upon arrival, you'll need to parse out the contents of the <script> tags and pass that string into eval() to execute it.
Typically you'd use a function like getElementsByTagName('script') to find the scripts in the response, grab their innerText.