javascript - Radio button validation causing rest of validation to fail -
the radio validation works rest don't. have done wrong?
function validateradio(radios) { (i = 0; < 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 how update order."); return false; } } var x = document.forms["pancettaform"]["order-number"].value; if (x == null || x == "") { alert("please provide order number."); return false; } var x = document.forms["pancettaform"]["full-name"].value; if (x == null || x == "") { alert("please provide full name, or recipients name if updating shipping information."); return false; } var x = document.forms["pancettaform"]["phone"].value; if (x == null || x == "") { alert("please provide 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 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 city."); return false; } } var display = document.getelementbyid('state').style.display; if (display == 'block') { if (document.pancettaform.state.value == "- select state -") { alert("please provide 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 zip code."); return false; } } var display = document.getelementbyid('newshipdate').style.display; if (display == 'block') { if (document.pancettaform.state.value == "- select date -") { alert("please choose new shipping date."); return false; } }
just reverse test not have return
if(!validateradio (document.forms["pancettaform"]["updateship"])) { alert("please tell how update order."); return false; } // continue
you had end bracket after test of radios rest of script floated in cyberspace
also return true once @ end , not have var x multiple times , consistent in how access form elements , fixed date test testing state
function validateform() { var x,display,form = document.forms["pancettaform"]; if (!validateradio(form["updateship"])) { alert("please tell how update order."); return false; } x = form["order-number"].value; if (x == null || x == "") { alert("please provide order number."); return false; } x = form["full-name"].value; if (x == null || x == "") { alert("please provide full name, or recipients name if updating shipping information."); return false; } x = form["phone"].value; if (x == null || x == "") { alert("please provide 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 address."); return false; } } display = form["city"].style.display; if (display == 'block') { x = form["city"].value; if (x == null || x == "") { alert("please provide city."); return false; } } display = form['state'].style.display; if (display == 'block') { x = form['state'].value; if (x == "- select state -") { alert("please provide state."); return false; } } display = form['zip'].style.display; if (display == 'block') { x = form["zip"].value; if (x == null || x == "") { alert("please provide zip code."); return false; } } display = form["newshipdate"].style.display; if (display == 'block') { x = form["newshipdate"].value; if (x.value == "- select date -") { alert("please choose new shipping date."); return false; } } return true; }
Comments
Post a Comment