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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:22:22+00:00 2026-05-31T18:22:22+00:00

I have JavaScript form validation functions like so: function validate_name(field) { if (field ==

  • 0

I have JavaScript form validation functions like so:

function validate_name(field) 
{
    if (field == "") return "Please enter the name.\n";
    return "";
}

function validate_specialty(field) 
{
    if (field == "") return "Please enter the specialty.\n";
    return "";
}

function validate_location(field) 
{
    if (field == "") return "Don't forget the location.\n";
    return "";
}

where the function that is called from the form’s onSubmit is:

function validate_fields(form)
{
    fail  = validate_name(form.name.value);
    fail += validate_specialty(form.specialty.value);
    fail += validate_location(form.location.value);

    if (fail == "")     
        return true;
    else 
    { 
        alert(fail); 
        return false;
    }
}

This works fine but I have decided that I don’t want all three to necessarily be required. It would be great if I could make these three optional, such that if any one of these fields is filled in, it would validate true, but if all three fields are empty, I could throw an alert and validate false.

Any help is much appreciated.

  • 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-05-31T18:22:23+00:00Added an answer on May 31, 2026 at 6:22 pm

    You can do that by capturing the results separately, and testing with an OR grouping.

    function validate_fields(form)
    {
        fail1 = validate_name(form.name.value);
        fail2 = validate_specialty(form.specialty.value);
        fail3 = validate_location(form.location.value);
    
        if (fail1 == "" || fail2 == "" || fail3 == "")     
            return true;
        else 
        { 
            alert(fail1 + fail2 + fail3); 
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that contains messages for form field validation. However I would
I have a Javascript form validator function something like switch (element.getAttribute('validationtype')) { case 'text':
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
Possible Duplicate: JavaScript post request like a form submit I have a value calculated
I have a php form that gets validated through javascript. I would like to
I am building a form, where required field validation must have been checked. I
I have a javascript function that posts data to a validation script and grabs
I have a very simple form with a name field and two submit buttons:
I have a form, when I typed it out like this: <form name=formLogin id=formLogin
I have been requested to create a simple form with JavaScript validation code. I

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.