title: javascript form validation. Check for input
body: <p>I have a form with three inputs, one for City, State, and Zipcode. Using javascript I need a simple way to check if the input for City contains a value. If the input does contain a value, I then need to check if State contains a value. If city contains a value, but state does not, I then need to trigger an alert box asking the user to enter a state.</p>
  
  <p>This is my form code, Thanks in advance!!</p>
  
  <pre><code>&lt;form action="home.php" method="post" name="location"&gt;
       Please enter....&lt;br /&gt;&lt;br /&gt;&lt;label&gt;city: 
       &lt;input type="text" name="city" size="10"/&gt;&lt;/label&gt;
       &lt;br /&gt;&lt;label&gt;state: 
       &lt;select id="state" name="state"&gt;
           &lt;option value="AL"&gt;Alabama&lt;/option&gt;
       &lt;option value="AK"&gt;Alaska&lt;/option&gt;
       &lt;option value="AZ"&gt;Arizona&lt;/option&gt;
       &lt;option value="AR"&gt;Arkansas&lt;/option&gt;
       &lt;option value="CA"&gt;California&lt;/option&gt;
       &lt;option value="CO"&gt;Colorado&lt;/option&gt;
       &lt;option value="CT"&gt;Connecticut&lt;/option&gt;
       &lt;option value="DE"&gt;Delaware&lt;/option&gt;
       &lt;option value="DC"&gt;District Of Columbia&lt;/option&gt;
       &lt;option value="FL"&gt;Florida&lt;/option&gt;
       &lt;option value="GA"&gt;Georgia&lt;/option&gt;
       &lt;option value="HI"&gt;Hawaii&lt;/option&gt;
       &lt;option value="ID"&gt;Idaho&lt;/option&gt;
       &lt;option value="IL"&gt;Illinois&lt;/option&gt;
       &lt;option value="IN"&gt;Indiana&lt;/option&gt;
       &lt;option value="IA"&gt;Iowa&lt;/option&gt;
       &lt;option value="KS"&gt;Kansas&lt;/option&gt;
       &lt;option value="KY"&gt;Kentucky&lt;/option&gt;
       &lt;option value="LA"&gt;Louisiana&lt;/option&gt;
       &lt;option value="ME"&gt;Maine&lt;/option&gt;
       &lt;option value="MD"&gt;Maryland&lt;/option&gt;
       &lt;option value="MA"&gt;Massachusetts&lt;/option&gt;
       &lt;option value="MI"&gt;Michigan&lt;/option&gt;
       &lt;option value="MN"&gt;Minnesota&lt;/option&gt;
       &lt;option value="MS"&gt;Mississippi&lt;/option&gt;
       &lt;option value="MO"&gt;Missouri&lt;/option&gt;
       &lt;option value="MT"&gt;Montana&lt;/option&gt;
       &lt;option value="NE"&gt;Nebraska&lt;/option&gt;
       &lt;option value="NV"&gt;Nevada&lt;/option&gt;
       &lt;option value="NH"&gt;New Hampshire&lt;/option&gt;
       &lt;option value="NJ"&gt;New Jersey&lt;/option&gt;
       &lt;option value="NM"&gt;New Mexico&lt;/option&gt;
           &lt;option value="NY"&gt;New York&lt;/option&gt;
       &lt;option value="NC"&gt;North Carolina&lt;/option&gt;
           &lt;option value="ND"&gt;North Dakota&lt;/option&gt;
       &lt;option value="OH"&gt;Ohio&lt;/option&gt;
       &lt;option value="OK"&gt;Oklahoma&lt;/option&gt;
       &lt;option value="OR"&gt;Oregon&lt;/option&gt;
       &lt;option value="PA"&gt;Pennsylvania&lt;/option&gt;
       &lt;option value="RI"&gt;Rhode Island&lt;/option&gt;
       &lt;option value="SC"&gt;South Carolina&lt;/option&gt;
       &lt;option value="SD"&gt;South Dakota&lt;/option&gt;
       &lt;option value="TN"&gt;Tennessee&lt;/option&gt;
       &lt;option value="TX"&gt;Texas&lt;/option&gt;
       &lt;option value="UT"&gt;Utah&lt;/option&gt;
       &lt;option value="VT"&gt;Vermont&lt;/option&gt;
       &lt;option value="VA"&gt;Virginia&lt;/option&gt;
       &lt;option value="WA"&gt;Washington&lt;/option&gt;
       &lt;option value="WV"&gt;West Virginia&lt;/option&gt;
       &lt;option value="WI"&gt;Wisconsin&lt;/option&gt;
       &lt;option value="WY"&gt;Wyoming&lt;/option&gt;
       &lt;/select&gt;&lt;/label&gt;&lt;br /&gt;
       or &lt;br /&gt;zipcode 
       &lt;input type="text" name="zipcode" size="6" /&gt;&lt;br /&gt;
       &lt;br /&gt;&lt;input type="submit" value="search" /&gt;
  &lt;/form&gt;`
  </code></pre>