title: Defining JavaScript function within PHP page
body: <p>I'm running into an issue with calling a JavaScript function from the <code>onclick</code> event of a span object.</p>
  <p>Here is the span object:</p>
  <pre><code>&lt;td&gt;&lt;span class=&quot;button&quot; onclick=&quot;submitUser();&quot;&gt;Save&lt;/span&gt;&lt;/td&gt;
  </code></pre>
  <p>Here is the JavaScript function that I am trying to embed at the top of the PHP page that the save button is found on:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  
      submitUser = function()
      {
          alert('hello');
      }
  
  &lt;/script&gt;
  </code></pre>
  <p>I keep getting the JavaScript error:</p>
  <blockquote>
  <p>&quot;Uncaught reference error: submitUser() is not defined&quot;</p>
  </blockquote>
  <p>If I define the JavaScript function on the same page as the save button. But if I put the function definition on the page calling the page containing the save button, the function works just fine. Is there a way that I can get that function in the the save button's page scope. I really don't want to have to load that function into memory every time the page calling the save button page is loaded, which is currently the only way I can get this to work.</p>