title: onsubmit event not working for asynchronous form submit
body: <p>I have created a form using struts tags. I have submitted the form asynchronously using struts jQuery's submit tag. Now before I submit my form i want to call a JavaScript function <code>checkUser()</code>, that checks if there is some client side error And prevents the form from submitting. The form with the JavaScript function is as follows:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
      function loadXMLDoc() {
          
          var xmlhttp;
          var k = document.getElementById(&quot;register_userDetails_username&quot;).value;
          
          var urls = &quot;pass.jsp?ver=&quot; + k;
  
          if (window.XMLHttpRequest) {
              xmlhttp = new XMLHttpRequest();
          } else {
              xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
          }
          xmlhttp.onreadystatechange = function() {
              if (xmlhttp.readyState == 4) {
                  document.getElementById(&quot;err1&quot;).innerHTML = xmlhttp.responseText;
              }
          };
          xmlhttp.open(&quot;GET&quot;, urls, true);
          xmlhttp.send();
      }
  &lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
        function checkuser() {
            alert(&quot;hi&quot;);  
              var i = document.getElementById('err1').innerHTML.search(&quot;Unavailable&quot;);
              alert(i);
              var j= document.getElementById('err1').innerHTML.search(&quot;Min length:8&quot;);
              alert(j);
              if (i!= -1 || j!=-1) {
                  alert(&quot;hello&quot;);
                  return false;
              } 
              alert(&quot;false&quot;);
              return false;
        } 
       
  &lt;/script&gt;
  
  
      
  &lt;%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%&gt;
  &lt;%@ taglib prefix=&quot;sj&quot; uri=&quot;/struts-jquery-tags&quot;%&gt;
  &lt;jsp:include page=&quot;menubar.jsp&quot;&gt;&lt;/jsp:include&gt;
  &lt;s:form action=&quot;register&quot; method=&quot;post&quot; theme=&quot;css_xhtml&quot; cssClass=&quot;form1&quot; style=&quot;margin:8px 211px&quot; onsubmit=&quot;return checkuser()&quot;&gt;
      &lt;div class=&quot;searchHeader&quot;&gt;Sign Up&lt;/div&gt;  
      &lt;div id=&quot;passwordMatchError&quot;&gt;
          &lt;s:property value=&quot;error&quot;/&gt;
      &lt;/div&gt;
      &lt;s:textfield label=&quot;Name&quot; name=&quot;userDetails.name&quot; maxlength=&quot;30&quot;/&gt;
      &lt;s:textfield label=&quot;Username&quot;  name=&quot;userDetails.username&quot; onkeyup=&quot;loadXMLDoc()&quot; maxlength=&quot;30&quot;&gt;
          &lt;div id=&quot;err1&quot;&gt;&lt;/div&gt;
      &lt;/s:textfield&gt; 
      &lt;s:password label=&quot;Password&quot; name=&quot;userDetails.password&quot; maxlength=&quot;45&quot;/&gt;
      &lt;s:hidden name=&quot;userDetails.role&quot; value='U' /&gt;
      &lt;s:password name=&quot;confirmPassword&quot; label=&quot;Confirm Password&quot; maxlength=&quot;45&quot;/&gt;
      &lt;s:radio label=&quot;Sex&quot; name=&quot;userDetails.sex&quot; list=&quot;#{'M':'Male','F':'Female'}&quot; /&gt;
      &lt;s:textfield label=&quot;Phone No&quot; name=&quot;userDetails.phoneno&quot; maxlength=&quot;10&quot;/&gt;
      &lt;s:textfield label=&quot;E-mail&quot; name=&quot;userDetails.email&quot; maxlength=&quot;45&quot;/&gt;
      &lt;div id=&quot;submitdivid&quot;&gt; 
          &lt;sj:submit value=&quot;SUBMIT&quot; cssClass=&quot;orangebuttonsmall&quot; targets=&quot;mainContent&quot; id=&quot;sas&quot; /&gt;
      &lt;/div&gt;
  &lt;/s:form&gt;
  </code></pre>
  <p>Now when I enter some value in username field that already exist in db, then it shows string <code>Unavailable</code> in div having id as <code>err</code>.</p>
  <p>On <code>onsubmit</code> event of form , I have called <code>checkuser</code> method. But with <code>sj:submit</code>, <code>onsubmit</code> event is <em>not</em> working. Can anyone help me with how to call make this <code>onsubmit</code> work My aim is to prevent form from submitting, if there exists the String <code>Unavailable</code> or <code>Min Length:8</code> in div <code>err</code>. Any alternative solutions are also accepted.</p>