title: How do I prevent my form from submitting if one of the fields is blank (JSP)?
body: <p>Below is my JSP file, and I was using a servlet to check if the fields are null, but apparently this needs to be done on the client side. How do I prevent the form from submitting when the submit button is pressed and a field is empty?</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ page session="false" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;style type="text/css"&gt;
  h1 { font-family : cooper black;}
  &lt;/style&gt;
  &lt;title&gt;Add a Phonebook Entry&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt; Add a Phonebook Entry&lt;/h1&gt;
  &lt;form action="process.do" method="GET"&gt;
  &lt;table summary="phonebook entry table"&gt;
      &lt;tr&gt;
          &lt;td&gt;Last name:&lt;/td&gt;
  
          &lt;%
          String last = "";
          String first = "";
          String phone = "";
  
          if(request.getParameter("surname")!=null){
              last = (String) request.getParameter("surname");
          }
          if(request.getParameter("firstname")!=null){
              first = (String) request.getParameter("firstname");
          }
  
          if(request.getParameter("phone")!=null){
              phone = (String) request.getParameter("phone");
          }
           %&gt;
  
          &lt;td&gt;&lt;input type="text" title="enter your last name here" name="surname" name="initials" size=10 maxlength=10 value=&lt;%= last %&gt; &gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;First name:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="firstname" size=10 maxlength=10 value=&lt;%=first %&gt; &gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Phone number: &lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="phone" maxlength=10 size=10 value=&lt;%=phone %&gt; &gt; &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br&gt;&lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;p&gt; View the phonebook &lt;a href="./Display.jsp"&gt;here&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p>
  </p>