Radio button validation causing rest of validation to fail

The radio validation works but then the rest don't. What have I done wrong?

function validateRadio(radios) {
    for (i = 0; i < radios.length; ++i) {
        if (radios[i].checked) return true;
    }
    return false;
}

function validateForm() {
    if (validateRadio(document.forms["pancettaForm"]["updateShip"])) {
        return true;
    } else {
        alert("Please tell us how you would like to update your order.");
        return false;
    }
}

var x = document.forms["pancettaForm"]["order-number"].value;
if (x == null || x == "") {
    alert("Please provide your order number.");
    return false;
}
var x = document.forms["pancettaForm"]["full-name"].value;
if (x == null || x == "") {
    alert("Please provide your full name, or the recipients name if you are updating shipping information.");
    return false;
}
var x = document.forms["pancettaForm"]["phone"].value;
if (x == null || x == "") {
    alert("Please provide a phone number in case of delivery questions.");
    return false;
}
var display = document.getElementById('address').style.display;
if (display == 'block') {
    var x = document.forms["pancettaForm"]["address"].value;
    if (x == null || x == "") {
        alert("Please provide your address.");
        return false;
    }
}
var display = document.getElementById('city').style.display;
if (display == 'block') {
    var x = document.forms["pancettaForm"]["city"].value;
    if (x == null || x == "") {
        alert("Please provide your city.");
        return false;
    }
}
var display = document.getElementById('state').style.display;
if (display == 'block') {
    if (document.pancettaForm.state.value == "- Select State -") {
        alert("Please provide your state.");
        return false;
    }
}
var display = document.getElementById('zip').style.display;
if (display == 'block') {
    var x = document.forms["pancettaForm"]["zip"].value;
    if (x == null || x == "") {
        alert("Please provide your zip code.");
        return false;
    }
}
var display = document.getElementById('newShipDate').style.display;
if (display == 'block') {
    if (document.pancettaForm.state.value == "- Select Date -") {
        alert("Please choose your new shipping date.");
        return false;
    }
}

Answers


Just reverse the test so you do not have to return

    if(!validateRadio (document.forms["pancettaForm"]["updateShip"]))
            {
                alert("Please tell us how you would like to update your order.");
                return false;
            }

   // continue

You had the end bracket after the test of the radios so the rest of the script just floated in cyberspace

Also return true only once at the end and do not have var x multiple times and be consistent in how you access the form elements and I also fixed your date test which was testing state

function validateForm() {
  var x,display,form = document.forms["pancettaForm"];
  if (!validateRadio(form["updateShip"])) {
    alert("Please tell us how you would like to update your order.");
    return false;
  }

  x = form["order-number"].value;
  if (x == null || x == "") {
    alert("Please provide your order number.");
    return false;
  }
  x = form["full-name"].value;
  if (x == null || x == "") {
    alert("Please provide your full name, or the recipients name if you are updating shipping information.");
    return false;
  }
  x = form["phone"].value;
  if (x == null || x == "") {
    alert("Please provide a phone number in case of delivery questions.");
    return false;
  }
  display = form["address"].style.display; 
  if (display == 'block') {
    x = form["address"].value;
    if (x == null || x == "") {
        alert("Please provide your address.");
        return false;
    }
  }
  display = form["city"].style.display;
  if (display == 'block') {
    x = form["city"].value;
    if (x == null || x == "") {
        alert("Please provide your city.");
        return false;
    }
  }
  display = form['state'].style.display;
  if (display == 'block') {
   x = form['state'].value;
    if (x == "- Select State -") {
        alert("Please provide your state.");
        return false;
    }
  }
  display = form['zip'].style.display;
  if (display == 'block') {
    x = form["zip"].value;
    if (x == null || x == "") {
        alert("Please provide your zip code.");
        return false;
    }
  }
  display = form["newShipDate"].style.display;
  if (display == 'block') {
    x = form["newShipDate"].value;
    if (x.value == "- Select Date -") {
        alert("Please choose your new shipping date.");
        return false;
    }
  }

  return true;
}

Need Your Help

Dropdown Rows with AngularJS

javascript angularjs angularjs-ng-repeat

I have a following table of grouped items:

Performance of Flex/AIR applications on ios/Android

android ios4 air flex4.5 flex-mobile

I want to know what are the limitions/Restrictions and the Performance of an AIR application for iOS/Android devices such as ipad2,galacy tabs.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.