title: JavaScript is Preceding Operation Before Clicking the "Submit" Button/Link
body: <p>I am new to JavaScript, and I am having a little difficulty getting my operation to perform correctly.  The program is running my code before I click on my submit button.  There are many similar questions that have been covered so far, but I don't believe any of them have covered this exact issue.  Please refrain from flagging this as answered elsewhere (believe me, I read those documents).  Thanks in advance for the help.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body style="background-color: lightgrey"&gt;
  &lt;link rel='stylesheet' type='text/css' href='newcss.css'/&gt;
  &lt;ol&gt;
      &lt;p style="color:black"&gt;Scan Location&lt;/p&gt;
  &lt;/ol&gt;
  
  &lt;table class="scanLocation" align="center"&gt;
         &lt;tr&gt;
             &lt;td&gt;
                 &lt;ol&gt;
                      &lt;input type="text" name="fname" maxlength= "18" size= "33" input style="font-size:20px"/&gt;
  
                 &lt;/ol&gt;
             &lt;/td&gt;
         &lt;/tr&gt;
         &lt;tr&gt;
             &lt;td&gt;
                 &lt;ol&gt;
                     &lt;form&gt;
                          &lt;input type="button" onclick="script" value="Submit"/&gt;
                              &lt;p id="seconds"&gt;&lt;/p&gt;
                                  &lt;script&gt;
                                      firstFunction();
                                      function firstFunction(){
                                      var date = new Date();
                                      var seconds = date.getUTCSeconds();
                                          myFunction();
                                          function myFunction(){
                                          document.getElementById("seconds").innerHTML = "seconds";
                                          }
                                          checkEven();
                                          function checkEven(seconds){
                                          return Math.floor(seconds%2) == Math.floor(0);
                                          }
                                          if(checkEven(seconds)){
                                              location.href='index2.jsp';
                                          }
                                          else{
                                              location.href='index3.jsp';
                                          }
                                          }
                                  &lt;/script&gt;
                     &lt;/form&gt;
                 &lt;/ol&gt;
             &lt;/td&gt;
         &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;script type='text/javascript' src='script.js'&gt;&lt;/script&gt;
  &lt;/html&gt;
  </code></pre>