title: Form submit button onClick JavaScript function
body: <p>I made a simple form with radio buttons and submit button. On submit, check() function is called and it prints out text dependent on which radio button is selected.</p>
  
  <p>But, it only works when I submit for the second time. First time I sumbit, page refreshes, ?req=on is added in the url, and that's it.</p>
  
  <p>Why is that, and how can I get it to work every time I press the submit button?</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form name="request" onsubmit="return check();"&gt;
      &lt;p&gt;
          &lt;label&gt;Pick fragments: &lt;/label&gt;
      &lt;/p&gt;
      &lt;fieldset&gt;
          &lt;input id="rally" type="radio" name="req" /&gt;
          Longest rally
          &lt;br /&gt;
          &lt;input id="gamept" type="radio" name="req" /&gt;
          Game points
          &lt;br /&gt;
          &lt;input id="setpt" type="radio" name="req" /&gt;
          Set points
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;input type="submit" /&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  
  &lt;ul id="uri"&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>And part of the script:</p>
  
  <pre><code>function check() {
  
      window.location.hash = "article6";
      var uri = new Array();
      var vid = new Array();
      $('#uri').empty();
  
      if($('#rally')[0].checked) {
  
          //get json with the longest rally and print it out
          $.getJSON('json/longRally.json', function(json) {
              for(var i = 0; i &lt; json["results"]["bindings"].length; i++) {
                  uri[i] = json["results"]["bindings"][i]["longRally"].value
                  vid[i] = json["results"]["bindings"][i]["uriRally"].value
  
              };
  
              uri.sort(alphanum);
              vid.sort(alphanum);
  
              for(var i = 0; i &lt; json["results"]["bindings"].length; i++) {
                  $('#uri').append('&lt;li&gt;&lt;a href="' + vid[i] + '"&gt;' + uri[i] + '&lt;/a&gt;&lt;/li&gt;');
              };
          });
      }   
  }
  </code></pre>
  
  <p>Web is located here:</p>
  
  <p><a href="http://b-webdesign.com/multilab/Ver3.0/#article6" rel="nofollow">http://b-webdesign.com/multilab/Ver3.0/#article6</a></p>