title: Radio button validation form for javascript
body: <p>Trying to validate a radio button (along with other validations); however, whenever it gets to the validation of the radio button, everything gets reset and does not even say "The form has been submitted" or validate the next part of the form.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function submit() {
    alert("The form was submitted");
  }
  
  
  function validate() {
    if (document.myForm.user.value.length &lt; 6) {
      alert("Please enter a username that is at least 6 characters long");
      document.myForm.user.focus();
      return false;
    }
  
    if (document.myForm.pass.value.length &lt; 6) {
      alert("Please enter a password that is at least 6 characters long.");
      document.myForm.pass.focus();
      return false;
    }
  
    if (document.myForm.pass.value != document.myForm.pass1.value) {
      alert("Your passwords do not match! Please re-enter your password!");
      document.myForm.pass1.focus();
      return false;
    }
  
    if (document.myForm.first.value == "") {
      alert("Please provide your First name!");
      document.myForm.first.focus();
      return false;
    }
  
    if (document.myForm.last.value == "") {
      alert("Please provide your Last name!");
      document.myForm.last.focus();
      return false;
    }
  
    if (document.myForm.address.value == "") {
      alert("Please provide your Address!");
      document.myForm.address.focus();
      return false;
    }
  
    if (document.myForm.city.value == "") {
      alert("Please provide your City!");
      document.myForm.city.focus();
      return false;
    }
  
    if (document.myForm.state.value == "") {
      alert("Please provide your State!");
      document.myForm.state.focus();
      return false;
    }
  
    if (document.myForm.zip.value == "" ||
      document.myForm.zip.value.length != 5) {
      alert("Please provide a Zip code in the format #####.");
      document.myForm.zip.focus();
      return false;
    }
    var zip = /^[0-9a]+$/;
    if (!document.myForm.zip.value.match(zip)) {
      alert("Please only enter numeric characters for the Zip code");
      document.myForm.zip.focus();
      return false;
    }
  
    if (document.myForm.creditcard[0].checked = true) {
      return true;
    } else if (document.myForm.creditcard[1].checked == true) {
      return true;
    } else if (document.myform.creditcard[2].checked == true) {
      return true;
    } else {
      alert("Please choose your credit card type!");
      return false;
    }
  
    if (document.myForm.creditno.value == "" ||
      document.myForm.creditno.value.length &lt; 13) {
      alert("Please provide a valid credit card number!");
      document.myForm.creditno.focus();
      return false;
    }
  
    if (!document.myForm.creditno.value.match(zip)) {
      alert("Please provide a valid credit card number!");
      document.myForm.creditno.focus();
      return false;
    }
  
    alert("The form was submitted");
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;p&gt;
    &lt;form action="" name="myForm" onsubmit="return (validate())" ;&gt;
      Username:
      &lt;input name="user" type="text" size="25"&gt;
      &lt;br&gt;Password:
      &lt;input name="pass" type="password" size="20"&gt;
      &lt;br&gt;Confirm Password:
      &lt;input name="pass1" type="password" size="20"&gt;
      &lt;br&gt;First Name:
      &lt;input name="first" type="text" size="30"&gt;
      &lt;br&gt;Last Name:
      &lt;input name="last" type="text" size="30"&gt;
      &lt;br&gt;
      &lt;br&gt;Address:
      &lt;input name="address" type="text" size="50"&gt;
      &lt;br&gt;City:
      &lt;input name="city" type="text" size="35"&gt;
      &lt;br&gt;State:
      &lt;input name="state" type="text" size="25"&gt;
      &lt;br&gt;Zip Code:
      &lt;input name="zip" type="text" size="5"&gt;
      &lt;br&gt;
      &lt;br&gt;**Credit Card:
      &lt;br&gt;
      &lt;input name="creditcard" type="radio"&gt;Visa
      &lt;br&gt;
      &lt;input name="creditcard" type="radio"&gt;Mastercard
      &lt;br&gt;
      &lt;input name="creditcard" type="radio"&gt;American Express
      &lt;br&gt;
      &lt;br&gt;** Credit Card #.
      &lt;input name="creditno" type="password" size="25"&gt;
      &lt;br&gt;
      &lt;br&gt;We welcome your comments and feedback:
      &lt;br&gt;
      &lt;textarea maxlength="100"&gt;&lt;/textarea&gt;
      &lt;br&gt;
      &lt;input type=submit value="Submit Query"&gt;
      &lt;input type=reset&gt;
  
    &lt;/form&gt;
  
  &lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>