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 9220361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:19:43+00:00 2026-06-18T03:19:43+00:00

I am trying to validate few textboxes in a form before doing other functionality

  • 0

I am trying to validate few textboxes in a form before doing other functionality in code behind so I got :

var validForm; // **If i set it there to true it will always be true**
            $('#Form :input').each(function () {
                var id = this.id;
                var value = this.value;
                var isMatch = id.substring(0, 4) == "txt_";

                if (isMatch == true) {
                    if (($.trim(value) == 0 ) {
                        alert("invalid " + id);
                        valid = false;
                    } // **if I include a else here it will not be valid as it is foreach loop**

                }
            });

            if (validForm == true) {
                $.ajax({
                    type: "POST",
                    url: "Form.aspx/Print",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (msg) {
                        if (msg.d == 'Success') {
                        }
                    }

                });
            }

if I do an else statement in foreach loop and set validForm variable to true it will not work as say the last textbox is valid and rest invalid then it will set my variable to true (see code comments).

On the other hand, if I assign validForm a true at the begining then it will always be true(see code comments).

any ideas of how to overcome this issue?

  • 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-18T03:19:44+00:00Added an answer on June 18, 2026 at 3:19 am

    At line number 10 you are using a wrong variable :

    valid = false;
    

    It should be like this :

    validForm = false; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use jQuery validation plugin to validate a few form fields by
I'm trying to validate emails but my code is not allowing a few scenarios..
While trying to validate form data on my page i get the following error:
i am trying to validate someone else's code here and they are using the
I'm trying to validate a few python arguments. Until we get the new static
I am trying to validate a few XML files and I'm failing due to
I am trying to validate a form using ModelState generally the same way as
I am trying to set up a WCF Service but I'm having a few
I am trying to validate the form fields by creating my own jquery function
When trying to validate my site, I get the following error: Line 188, column

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.