call javascript function from html generated by another javascript function
<p>I'm a newbie in javascript. As the title says, I'm trying to call javascript function from html generated by another javascript function. Following is a simple version of this code:</p>

<pre><code>&lt;HTML&gt;
   &lt;HEAD&gt;
   &lt;SCRIPT language="JavaScript"&gt;
      function myFunction1()
      {
         var html_text = "&lt;HTML&gt;&lt;BODY&gt;&lt;FORM&gt;&lt;INPUT type=\"button\" onClick=

\"myFunction2()\" value=\"function2\" /&gt;&lt;/FORM&gt;&lt;/BODY&gt;&lt;/HTML&gt;";
         document.write(html_text);
         document.close();
      }

      function myFunction2()
      {
         alert("function2 called!");
      }
   &lt;/SCRIPT&gt;
   &lt;/HEAD&gt;
   &lt;BODY&gt;
      &lt;FORM&gt;&lt;INPUT type="button" onClick="myFunction1()" value="function1" 

/&gt;&lt;/FORM&gt;
   &lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>When I run firebug, I got an error saying "myFunction2 is not defined". I guess I have to put myFunction2 in html code generated by myFunction1. So I changed my code like this:</p>

<pre><code>&lt;HTML&gt;
   &lt;HEAD&gt;
   &lt;SCRIPT language="JavaScript"&gt;
      function myFunction1()
      {
         var html_text = "&lt;HTML&gt;&lt;HEAD&gt;&lt;SCRIPT language=\"JavaScript

\"&gt;function myFunction2(){alert(\"function2 called!\");}

&lt;/SCRIPT&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;FORM&gt;&lt;INPUT type=\"button\" onClick=\"myFunction2()\" 

value=\"function2\" /&gt;&lt;/FORM&gt;&lt;/BODY&gt;&lt;/HTML&gt;";
         document.write(html_text);
         document.close();
      }

      /* function myFunction2()
      {
         alert("function2 called!");
      } */
   &lt;/SCRIPT&gt;
   &lt;/HEAD&gt;
   &lt;BODY&gt;
      &lt;FORM&gt;&lt;INPUT type="button" onClick="myFunction1()" value="function1" 

/&gt;&lt;/FORM&gt;
   &lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>However, after this change I got some messy result and the firebug says "unterminated string literal for var html_text=...". Any suggestions?
Also, my actual myFunction2 is really big, if I have to insert it into the html generated by myFunction1, is there a good way to put it in? Also, the instructor doesn't want us to use a separate file. Thanks!</p>
