title: How to call a javascript function on submit to assign a value to an input? (ACE Editor)
body: <p>My goal is to send the code inside the ACE Editor to as a variable to the <code>send.php</code> PHP file. I tried this in many different methods but I can't assign the code inside the editor to the form input.</p>
  
  <hr>
  
  <p><strong>JavaScript</strong></p>
  
  <p>This javascript function should assign a value to an element with the <code>id="code"</code>, which is: <code>&lt;input type="hidden" id="code" value="" /&gt;</code>.</p>
  
  <p><code>editor.getSession().getValue();</code> returns the code that is inside the editor.</p>
  
  <pre><code>&lt;head&gt;
   &lt;script&gt;
  
     function getVal() {
     document.getElementById('code').value = editor.getSession().getValue();
     }
  
   &lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <p>Now, <code>&lt;form onsubmit="getVal();"</code> should execute <code>function getVal()</code> when a user submits the form, so that the <code>code</code> input will have a value when sending the inputs to the <code>send.php</code> file.</p>
  
  <pre><code>&lt;body&gt;
  
    &lt;div&gt;
       &lt;form onsubmit="getVal();" method="post" action="send.php"&gt;
  
          &lt;label for="Name"&gt;From:&lt;/label&gt;
          &lt;input type="text" name="Name" id="Name" /&gt;
          &lt;label for="Address"&gt;To:&lt;/label&gt;
          &lt;input type="text" name="Address" id="Address" /&gt;
          &lt;label for="Subject"&gt;Subject:&lt;/label&gt;
          &lt;input type="text" name="Subject" id="Subject" /&gt;
  
          &lt;input type="hidden" id="code" value="" /&gt;
  
          &lt;div id="editor"&gt; //ACE Editor
          &lt;/div&gt;
  
          &lt;input type="submit"&gt;
  
       &lt;/form&gt;
    &lt;/div&gt;
  </code></pre>