title: How to trigger a function from onclick using Node.js
body: <p>I am new to using Azure, after using Google Apps Script to write web apps for many years. I needed to change how I was working die to some incompatibilities with iPhones. I was using javascript and HTML, so have recreated the app with node.js.</p>
  
  <p>I am able to return the html page, and run client side scripts, however I need to be able to trigger a server side script so I am not opening up the SQL database on the client side. </p>
  
  <p>The server.js script is as follows:</p>
  
  <pre><code>var http = require('http');
  var fs = require('fs');
  var path = require('path');
  
  http.createServer(function (req, res) {
    res.writeHead(200, {"Content-Type": "text/html"});
    fs.createReadStream(path.resolve(__dirname, 'HTMLPage.html')) 
      .pipe(res);
  }).listen(process.env.PORT || '3000'); // provide a default 
  
  
  function processForm(form) {
    var firstName = form.firstName;
    var lastName = form.lastName;
  console.log(firstName);
  } 
  </code></pre>
  
  <p>The HTMLPage contains the form code, and a button with an onsubmit command which triggers a client side script, however I can't seem to trigger the server side script (my attempt in bold). Can you please tell me where I am going wrong?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;script&gt;
  function post() {
    var first = document.getElementById("firstName").value;
    var last = document.getElementById("lastName").value;
  window.alert('Thanks, we will contact you soon.');
  
  processForm(form).init; //This is the bit which is not calling the script
  
   };
  &lt;/script&gt;
  
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;   
  &lt;/head&gt;
  
  &lt;body&gt;
     &lt;div id="formdiv"&gt;
         &lt;form id="form" onsubmit="post();"&gt;
         &lt;input type="firstName" class="form__input" id="firstName" name="firstName" /&gt;
         &lt;label class="form__label" for="firstName"&gt;&lt;span class="form__label-content"&gt;First Name&lt;/span&gt;&lt;/label&gt;
         &lt;input  type="lastName" class="form__input" id="lastName" name="lastName" /&gt;
         &lt;label class="form__label" for="lastName"&gt;&lt;span class="form__label-content"&gt;Last Name&lt;/span&gt;&lt;/label&gt;                          
         &lt;input  type="text" id="ddValues" name="ddValues" style="display:none" /&gt;
         &lt;input  type="submit" name="submit" class="btn btn-block" onclick="post();"&gt;
         &lt;/form&gt;
  </code></pre>
  
  <p>Instead of triggering the script, in the console I get this message:</p>
  
  <p>Uncaught ReferenceError: processForm is not defined
      at post 
      at HTMLInputElement.onclick</p>
  
  <p>Anyone know what I am missing here? Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Based on information from ruggierom &amp; naga - elixir - jar here is the updated  script. My results now give me 3 undefined objects.</p>
  
  <p>Server.js</p>
  
  <pre><code>var http = require('http');
  var fs = require('fs');
  var path = require('path');
  
  http.createServer(function (req, res) {
  
    res.writeHead(200, {"Content-Type": "text/html"});
    fs.createReadStream(path.resolve(__dirname, 'HTMLPage.html')) 
      .pipe(res);
  
    console.log(req.body);
  
  }).listen(process.env.PORT || '3000'); // provide a default 
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
     &lt;/head&gt;
  &lt;body&gt; 
  &lt;form id="form" name="form" method="post"&gt;
       &lt;input type="firstName" class="form__input" id="firstName" name="firstName" /&gt;
      &lt;input type="lastName" class="form__input" id="lastName" name="lastName" /&gt;                
      &lt;input type="submit" name="submit"&gt; 
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>