execute javascript dynamically
<pre><code>&lt;html&gt;
    &lt;body&gt;
        &lt;div id="div1"&gt;
        &lt;/div&gt;
        &lt;div id="div2"&gt;
            &lt;input type="button" value="Go!" onclick="go()" /&gt;
        &lt;/div&gt;
        &lt;script type="text/javascript"&gt;
            window.onload=function(){
                var newsc = "&lt;script id='sc1' type='text/javascript'&gt;function go() { alert('GO!') }&lt;\/script&gt;";
                var e = document.getElementById('div1');
                e.innerHTML = newsc;
                eval(document.getElementById('div1').innerHTML);
            }
        &lt;/script&gt;

    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This is my html page.when page loads <code>alert('Go')</code> is fired but this not what i am want to do. I would like to do is that when we click on <strong>Go</strong> button then <code>go</code> function should be called</p>

<p><strong>UPDATE:</strong></p>

<pre><code>$.ajax({
  url: 'ajax/js.php?id=123',
  success: function(data) {
   eval(data);
  }
});
</code></pre>

<p>this ajax request return different code on different id</p>
