title: Execute Javascript function before submitting the form
body: <p>I have the following spring form that execute back end controller and JavaScript function, everything work but I need to execute JavaScript function before submitting the form. How to do that?</p>
  
  <p>The following code submit the form before execute JavaScript.</p>
  
  <pre><code>&lt;form:form modelAttribute="api" id="form"&gt;
                  &lt;form:textarea path="text" class="form-control" rows="10" id="redacttext"/&gt;
                  &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
   &lt;/form:form&gt;
  </code></pre>
  
  <p>Javascript function</p>
  
  <pre><code>function dosomething() {
   //do something 
  }
  </code></pre>
  
  <p>Execute javascript function by jquery</p>
  
  <pre><code>$('#form').submit(function() {
        dosomething();
    });
  </code></pre>