title: JavaScript uncaught reference error using onclick attribute in input form tag
body: <p><strong>JavaScript Function</strong></p>
  
  <pre><code>function submitToServer(formObject)
  {           
          if(validateUserName(formObject["userName"]) &amp;&amp; validatePassword(formObject["password"])) 
          {
              formObject.submit();
          }
  }
  </code></pre>
  
  <p><strong>HTML FORM FIELD</strong></p>
  
  <pre><code> &lt;form  method="POST" action="SignIntoPortal"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt; User Name : &lt;/td&gt; 
                  &lt;td&gt;
                         &lt;input type="text" id="userName" name="userName" onblur="validateUserName(this)"&gt;
                         &lt;span id="userName_help" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt; Password : &lt;/td&gt; 
                  &lt;td&gt;
                         &lt;input type="password" id="password" name="password" onblur="validatePassword(this)"&gt;
                         &lt;span id="password_help" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;br&gt;
          &lt;/table&gt;
          &lt;input type="button" name="submitButton" id="submitButton" value="Submit" onclick="submitToServer(this.form);"&gt;
          &lt;/input&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>The above is my code, which validates data and submits the form. but i keep getting </p>
  
  <blockquote>
    <p>Uncaught ReferenceError: submitToServer is not defined</p>
  </blockquote>
  
  <p>error, which I am unable to resolve. what could be the reason?
  But, when I tried it with different form it worked with different names and fields.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>the difference between the code that worked and this is that, the former code does not use table it works smooth. Does scope change with table ?</p>
  
  <p>You can find the code here <a href="http://jsfiddle.net/saikumarm4/q9y6yqyx/10/" rel="nofollow">CODE FIDDLE</a></p>
  
  <p>You can get .html file <a href="http://www.4shared.com/document/4hMiWyp-ce/SignIn.html" rel="nofollow">here</a></p>
  
  <p><strong>SignIn.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Sign into Shopping Zone&lt;/title&gt;
          &lt;meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-8"&gt; 
          &lt;style&gt;
              body
              {
                  font: 14px verdana;
              }
              h1
              {
                  font: arial-black;
                  color: blue;
              }
          &lt;/style&gt;
  
          &lt;script type="javascript" language="text/javascript"&gt;
              function submitToServer(formObject)
              {           
                  if(validateUserName(formObject["userName"]) &amp;&amp; validatePassword(formObject["password"])) 
                  {
                      formObject.submit();
                  }
              }
              function validateUserName(inputField)
              {
                  if(inputField.value.length == 0)
                  {
                      document.getElementById("userName_help").innerHTML = "Please enter value";
                      return false;
                  } 
                  else
                  {
                      document.getElementById("userName_help").innerHTML = "";    
                      return true;
                  } 
              }
              function validatePassword(inputField)
              {
                  if(inputField.value.length == 0)
                  {
                      document.getElementById("password_help").innerHTML = "Please enter value";
                      return false;
                  }
                  else
                  {
                      document.getElementById("password_help").innerHTML = "";
                      return true;
                  }
              }
          &lt;/script&gt;
  
      &lt;/head&gt;
  
      &lt;body&gt;
  
          &lt;h1&gt;&lt;b&gt;&lt;i&gt;Shopping Zone&lt;/i&gt;&lt;/b&gt;&lt;/h1&gt;
          &lt;p&gt; Kindly Provide Login info
          &lt;/p&gt;
          &lt;!-- SignIn Form Data for Passing to SignIntoPortal--&gt;
          &lt;form  method="POST" action="SignIntoPortal"&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt; User Name : &lt;/td&gt; &lt;td&gt;&lt;input type="text" id="userName" name="userName" onblur="validateUserName(this)"&gt;&lt;span id="userName_help" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt; Password : &lt;/td&gt; &lt;td&gt;&lt;input type="password" id="password" name="password" onblur="validatePassword(this)"&gt;&lt;span id="password_help" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;br&gt;
              &lt;/table&gt;
              &lt;input type="button" name="submitButton" id="submitButton" value="Submit" onclick="submitToServer(this.form)"&gt;&lt;/input&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>