Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:00:08+00:00 2026-06-11T17:00:08+00:00

Please look at this code, and tell me why even when my errors DO

  • 0

Please look at this code, and tell me why even when my errors DO get triggered that my error variable still screams 0. I have tried and tried and tried to get them to change. I am just lost at this point.

validationError = 0;
$("#step1continue").click(function(){

        var fname = $('#fname');
        if (fname.val() == "") {
            fname.addClass("needsfilled");
            fname.val('Required!');
                       validationError = 1;
        } else {
                  validationError = 0;
        }

        var lname = $('#lname');
        if (lname.val() == "") {
            lname.addClass("needsfilled");
            lname.val('Required!');
                        validationError = 1;
        } else {
                 validationError = 0;
        }

        var company_name = $('#company_name');
        if (company_name.val() == "") {
            company_name.addClass("needsfilled");
            company_name.val('Required!');
                        validationError = 1;
        } else {
                  validationError = 0;
        }

        var email = $('#email');
        if (email.val() == "") {
            email.addClass("needsfilled");
            email.val('Required!');
                       validationError = 1;
        } else {
                  validationError = 0;
        }

         var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
               if (!emailReg.test(email.val())) {
                        email.addClass("needsfilled");
            email.val('Use a real email address!');
                       validationError = 1;
        } else {
                 validationError = 0;
        }

         var phone = $('#phone');
                if (phone.val() == "") {
            phone.addClass("needsfilled");
            phone.val('Required!');
                        validationError = 1;
        } else {
                  validationError = 0;
        }
                if (phone.val().length < 10) {
            phone.addClass("needsfilled");
            phone.val('10 digits minimum');
                        validationError = 1;
        } else {
                 validationError = 0;
        }   

                var phoneregxp = /^[0-9]$/;
                if (phoneregxp.test(phone.val())) {
                        phone.addClass("needsfilled");
            phone.val('Numbers ONLY');
                        validationError = 1;
        } else {
                  validationError = 0;
        }   

      alert(validationError);

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:00:10+00:00Added an answer on June 11, 2026 at 5:00 pm

    Because you continually reset your validationError on every successful check?

    If (say) #fname isn’t filled out, you set validationError to be 1. That’s fine. But then you check #lname, and oops… that’s one filled out, so now validationError is 0 again.

    Instead of a simple on/off value that gets yanked around like crazy, why not INCREMENT the value everytime there’s an error?

    validationError = 0;
    if (...) { validationError++ }
    if (...) { validationError++ }
    if (validationError > 0) {
       alert('You have ' + validationError + ' errors');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please have a look at this code and tell me what am
Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
Take a look at this code and please tell me how is it possible
Good day, could you please help me look and this code and tell me
an anyone look at this simple code (?) and tell me what's wrong please?
Please look at this code: @interface myObject:NSObject -(void)function:(id)param; @end @implementation myObject -(void)function:(id)param { NSLog(@BEFORE);
Please look at this code: def chop(array, search): lo = 0 high = len(array)
Please take a look at this code: template<class T> class A { class base
Look at this code please: #include <iostream> using namespace std; class Ratio { public:
There is some problem, i can't understand anyway. look at this code please <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.