title: JSP abort submit button if
body: <p>I have a <code>search.jsp</code> in which I can enter a number to find data in a database table. I want to pass the found data as parameters to another <code>.jsp</code> but ONLY if the submit button is clicked and ONLY if data was found in the table or database. Here's my code but it doesn't work correctly.</p>
  
  <pre><code>&lt;script&gt;
      var validation = new Boolean();
  
      function valid() {
          if(validation == false)
              return false;
          else {
              return true;
          }
      }
  &lt;/script&gt;
  
  &lt;form action="change.jsp" onsubmit="return valid();" &gt;
      &lt;br&gt; &lt;input type="text" name="searchAlbumNo"&gt; AlbumNo &lt;/input&gt;
      &lt;br&gt; &lt;input type="submit" value="Search" name="clicked"&gt; &lt;br&gt;   
  &lt;/form&gt;
  
  if(request.getParameter("clicked") == null ||  !(request.getParameter("clicked").equals("Search")))  {
      System.out.println(request.getParameter("clicked"));
              %&lt; &lt;script&gt; validation = false &lt;/script&gt; &lt;%
      } else {
          //... java code
          //... and if data found
          &lt;script&gt; validation = true &lt;/script&gt;
      }
  </code></pre>
  
  <p>Now the validation thing actually works but only once and the Java code is never accessed or executed. How can I solve this problem?</p>