title: Javascript Validation for Radio Buttons in a form with multiple Validations
body: <p>I'm having trouble finding a way to validate my Gender choice action buttons. I've made efforts at doing it by saying that the buttons can't be left null, but it still recognises one button as being null and won't let me continue. I've tried different variations of this like saying both male and female aren't selected then return false but it still won't work for me. I'm beginning to think that the method I'm going about it just may not be correct. The main issue you want to look at the below is the two radio buttons but I have included the rest of the code as context for the Javascript. The rest of the code works fine it is only the radio buttons than I'm struggling with. Thanks.</p>
  
  <p>Html</p>
  
  <pre><code>&lt;form action="ReviewPHP.php" name="review" onsubmit="return validateForm()"&gt; 
  
    &lt;fieldset&gt; 
      Title: &lt;input type="text" name="Title"&gt;
      &lt;/br&gt;
      Email Address: &lt;input type="text" name="Email"&gt;
      &lt;br/&gt; 
      Rating: &lt;select name="Rating"&gt; 
        &lt;option value="0"&gt;&lt;/option&gt; 
        &lt;option value="1"&gt;Excellent&lt;/option&gt; 
        &lt;option value="2"&gt;Good&lt;/option&gt; 
        &lt;option value="3"&gt;Bad&lt;/option&gt; 
        &lt;option value="4"&gt;Awful&lt;/option&gt; 
      &lt;/select&gt;
      &lt;br/&gt; 
      &lt;textarea name ="Comments" rows="8" colspan="40"&gt;Comments: 
      &lt;/textarea&gt; 
      &lt;br/&gt;
  
      &lt;input type="radio" name="Gender" id="male" value="male"&gt;Male
      &lt;input type="radio" name="Gender" id="female" value="female"&gt;Female
  
    &lt;/fieldset&gt; 
  
    &lt;fieldset&gt; 
      &lt;input class="button" type="submit" value="Submit"/&gt; 
    &lt;/fieldset&gt; 
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>function validateForm()
  { //Variable declarations for form inputs 
  
    var t = document.forms["review"]["Title"].value;
    var e = document.forms["review"]["Email"].value;
    var r = document.forms["review"]["Rating"].value;
    var c = document.forms["review"]["Comments"].value;
    var b = document.forms["review"]["Gender"].value;
    var atsymb = e.indexOf("@");
    var dotsymb = e.lastIndexOf(".");
  
    if (t == null || t == "") {
      document.getElementById("valAlert").innerHTML = "Title Missing";
      return false;
    }
  
    else if (e == null || e == "" || atsymb &lt; 1 || dotsymb &lt; atsymb + 2 || dotsymb + 2 &gt;= e.length)
    {
      document.getElementById("valAlert").innerHTML = "Email Missing";
      return false;
    }
  
    else if (r == "0") {
      document.getElementById("valAlert").innerHTML = "Please Rate the Movie, it's why you're here";
      return false;
    }
  
    else if (c == null || c == "" || c.length &lt; 10) {
      document.getElementById("valAlert").innerHTML = "Reviews gotta be at least 10 characters!";
      return false;
    }
  
    else if (b == null) {
      document.getElementById("valAlert").innerHTML = "Please select Gender";
      return false;
    }
  
    else {
      alert("Review for " + t + " has been submitted, Good Job!");
      return true;
    }
  } 
  </code></pre>