Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- $("#saveCustInfo").submit(function (e) {
- if (validateForm()) {
- return true;
- }
- alert("Please check the hilighted fields for errors.");
- e.preventDefault();
- });
- });
- function resetFields() {
- var fields = [
- "#firstname",
- "#lastname",
- "#mainTelephone",
- "#address1",
- "#city",
- "#state",
- "#postalcode",
- "#countryID",
- "#shipAddress1",
- "#shipCity",
- "#shipState",
- "#shipPostalcode",
- "#shipCountryID"
- ];
- for (var f in fields) {
- $(fields[f]).removeClass("error");
- }
- }
- function setFieldFail(f) {
- $('#' + f).addClass("error");
- }
- function validateForm() {
- var pass = true;
- resetFields();
- if ($("#firstname").val() == '') {
- setFieldFail("firstname");
- pass = false;
- }
- if ($("#lastname").val() == '') {
- setFieldFail("lastname");
- pass = false;
- }
- if ($("#mainTelephone").val() == '') {
- setFieldFail("mainTelephone");
- pass = false;
- }
- if ($("#address1").val() == '') {
- setFieldFail("address1");
- pass = false;
- }
- if ($("#city").val() == '') {
- setFieldFail("city");
- pass = false;
- }
- if ($("#state").val() == '') {
- setFieldFail("state");
- pass = false;
- }
- if ($("#postalcode").val() == '') {
- setFieldFail("postalcode");
- pass = false;
- }
- if ($("#countryID").val() == '') {
- setFieldFail("countryID");
- pass = false;
- }
- if ($("#shipAddress1").val() == '') {
- setFieldFail("shipAddress1");
- pass = false;
- }
- if ($("#shipCity").val() == '') {
- setFieldFail("shipCity");
- pass = false;
- }
- if ($("#shipState").val() == '') {
- setFieldFail("shipState");
- pass = false;
- }
- if ($("#shipPostalcode").val() == '') {
- setFieldFail("shipPostalcode");
- pass = false;
- }
- if ($("#shipCountryID").val() == '') {
- setFieldFail("shipCountryID");
- pass = false;
- }
- if (!pass) return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement