title: Using a button with JavaScript & HTML
body: <p>I know, the title seems to lead to a repetitive/useless question, but I can't find a solution in other questions. Let me explain better and read what follows before closing my question.</p>
  <p>I created a form by learning from different sources. It all seems to work fine, until I have to click on submit button, with &quot;Save as TXT&quot; written on it. It happens quite a strange thing:</p>
  <ul>
  <li>if I click on the text &quot;Save as TXT&quot; inside the button, it submits my data correctly;</li>
  <li>if I click on the coloured part around the text &quot;Save as TXT&quot; of the button, it refreshes the page.</li>
  </ul>
  <p>I think I found why this happens, but I can't fix it. It seems to be something which has to do with both my HTML code and my JavaScript code. Here it is a part of it:</p>
  <p><em>Javascript</em></p>
  <pre><code>$(function(){
      $(&quot;#submitLink&quot;).click(function(event){
  
         // things to do on submit...
  
  });
  });
  </code></pre>
  <p><em>HTML</em></p>
  <pre><code>&lt;form method=&quot;post&quot; name=&quot;myForm&quot; action=&quot;&quot; id=&quot;formToSave&quot;&gt;
  
      &lt;!-- some fields to compile... --&gt;
  
      &lt;div class=&quot;input-group mb-3&quot;&gt;
          &lt;button class=&quot;btn btn-primary btn-lg&quot; id=&quot;align&quot; type=&quot;submit&quot;&gt;&lt;a href=&quot;javascript://Save as TXT&quot; id=&quot;submitLink&quot;&gt;Save as TXT&lt;/a&gt;&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  <p>How can I change this part of the code in order to submit successfully by clicking anywhere on the button (and do what I write in the JS function)?</p>
  <p>Thanks in advance,</p>
  <p>happy coding everyone!</p>
  <p>ps. I read <a href="https://stackoverflow.com/questions/12319758/clicking-a-button-within-a-form-causes-page-refresh">this</a> &quot;famous&quot; question you added by after closing my question, but it is not helping me. By writing <code>type=&quot;button&quot;</code> instead of <code>type=&quot;submit&quot;</code> I get no results, I'm sorry</p>