title: I want to show alert(validate form) and don't submit if form was not valid in portlet liferay
body: <p>I have a form in my portlet in liferay 6. I want to validate data before sending data from form, but I cannot. I want that if my field is empty, the form does not submit.</p>
  
  <p>My jsp code:</p>
  
  <pre><code>&lt;script&gt;
  function submitForm18() {
      var pre=document.forms['&lt;portlet:namespace/&gt;myFormpostcode']['&lt;portlet:namespace/&gt;pre'].value;
      if (pre == "" || pre == null) {
          alert("errrror.");
          forms['&lt;portlet:namespace/&gt;myFormpostcode']['&lt;portlet:namespace/&gt;pre'].focus();
          return false;
      }
      document.forms['&lt;portlet:namespace/&gt;myFormpostcode'].submit();
  }  
  &lt;/script&gt;
  
  &lt;aui:form action="&lt;%= myUrl%&gt;" method="post" name="myFormpostcode" id="send_info" onsubmit="return submitForm18(); return false;"&gt;
      &lt;liferay-ui:message key="pre-code" /&gt;    :  &lt;liferay-ui:message key="without-zero" /&gt;
      &lt;aui:input size="4" maxlength="4" name="pre" type="text" label=""&gt;&lt;/aui:input&gt; 
      &lt;aui:button type="submit" value="send" name="KeyNB" cssClass="buttom-submit" /&gt;               
  &lt;/aui:form&gt;
  </code></pre>
  
  <p>This code shows alert if field is empty and submits form but I want to show alert(validate form) and don't submit if form data is not valid.</p>