title: HTML form field required if another field is not null
body: <p>Trying to get the &quot;location&quot; to be required <strong>if</strong> the &quot;name&quot; field is not null.
  I don't completely understand java or jQuery so the examples I've been looking at don't make sense. Sorry for being a noob but I've been googling for and just not seeing the solution.</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo htmlspecialchars($_SERVER[&quot;PHP_SELF&quot;]);?&gt;&quot;&gt;
      Name: &lt;input type=&quot;text&quot; name=&quot;name&quot; required&gt;
      &lt;label for=&quot;location&quot;&gt;Choose a location:&lt;/label&gt;
      &lt;select name=&quot;location&quot; id=&quot;location&quot;&gt;
        &lt;option value=&quot;ON&quot;&gt;Ontario&lt;/option&gt;
        &lt;option value=&quot;BC&quot;&gt;B.C.&lt;/option&gt;
        &lt;option value=&quot;AB&quot;&gt;Alberta&lt;/option&gt;
        &lt;option value=&quot;MI&quot;&gt;Michigan&lt;/option&gt;
      &lt;/select&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;&gt;
  &lt;/form&gt;
  </code></pre>