title: Cannot return from outside a function or method
body: <p>The line onclick="return Val();" shows an error Cannot return from outside a function or method and after execution of the JavaScript function form is getting submitted regardless the text field is blank or not.</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
              pageEncoding="ISO-8859-1"%&gt;
  
  
  
          &lt;html&gt;
          &lt;%if(session.getAttribute("status")==null){
              response.sendRedirect("atmHomeUser.jsp");
          }
              %&gt;
          &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;
          &lt;script&gt;
  
                  function Val(){
                      document.getElementById("m1").innerHTML="";
                      document.getElementById("m2").innerHTML="";
                      if(document.forms[0].oldPin.value.length == 0 || isNaN(document.forms[0].oldPin.value)){
                          document.getElementById("m1").innerHTML="Enter Old pin which must be numbers only";
                              return false;                 
                       }
                      else if(document.forms[0].newPin.value.length == 0 || isNaN(document.forms[0].newPin.value)){
                          document.getElementById("m2").innerHTML="Enter New pin  which must be numbers only";
                          return false;                 
                   }
                      else{
                          return true;
                          }
                      }
          &lt;/script&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;table width="100%" height="100%"&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;%@include file="atmAdmin.jsp"%&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr height="100%"&gt;
                      &lt;td colspan="2" align="center"&gt;
                          &lt;div style=""&gt;Enter old and new PIN&lt;/div&gt;
                          &lt;table style="font-family: verdana font-size : 38px" align="center"&gt;
  
                              &lt;tr&gt;
                                  &lt;td&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;form action="ChangePIN" method="post"&gt;
                              &lt;tr&gt;
                                  &lt;td font-size="28px"&gt;Enter Old PIN No.&lt;/td&gt;
                                  &lt;td&gt;&lt;input type="name" name="oldPin"&gt;
                                  &lt;/td&gt;&lt;td&gt;&lt;span id="m1" &gt;&lt;/span&gt;
                                      &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;br&gt;
                                  &lt;td&gt;&lt;/td&gt;
  
                              &lt;/tr&gt;
                              &lt;td&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td font-size="28px"&gt;Enter New Pin&lt;/td&gt;
                                  &lt;td&gt;&lt;input type="name" name="newPin"&gt;
                                  &lt;/td&gt;&lt;td&gt;&lt;span id="m2" &gt;&lt;/span&gt;
                                      &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;br&gt;
                                  &lt;td&gt;&lt;/td&gt;
                                  &lt;td align="center"&gt;&lt;input type="submit" value="submit" onclick="return Val();"&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;/form&gt;
                          &lt;/table&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr width="22px" valign="bottom"&gt;
                      &lt;td colspan="2"&gt;&lt;%@include file="atmFoot.jsp"%&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  
  
          &lt;/body&gt;
          &lt;/html&gt;
  </code></pre>
  
  <p>Please help me as I am a newbie. Also tell me how to convert javascript code to jquery.</p>