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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:38:45+00:00 2026-05-31T21:38:45+00:00

I want to refer to this post, because it might relate: Make Form Fields

  • 0

I want to refer to this post, because it might relate:

Make Form Fields Optional with JavaScript Validation

I have a form with three optional fields, as described above. If I click the submit button, the JavaScript alerts come up, but the last one is a URL instead of the string I specify in the JavaScript function (the one that isn’t an alert strong but an URL).

After a second, the page tries to go to an invalid URL:

localhost.../index.php/Don%27t%20forget%20the%20location.

As it turns out the Don%27t%20forget%20the%20location. is the alert string I have in the JavaScript function.

I thought that I might have some weird code that I accidentally pasted somewhere causing this but I scoured my files and found nothing out of the ordinary that would cause this. Not sure if this is a bug or something I’m doing wrong.

EDIT

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_form(form)
{
    name  = validate_name(form.name.value);
    specialty = validate_specialty(form.specialty.value);
    location = validate_location(form.location.value);

    if (name == "" || specialty == "" || location == "")
    {
        return true;
    }

    else 
    { 
        alert("You must enter at least one field:\n\n" + name + specialty + location);
        return false;
    }
}
  • 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-31T21:38:47+00:00Added an answer on May 31, 2026 at 9:38 pm

    It’s because the variable location refers to window.location in that case (the url). So if you change your variable name, that should work:

    userLocation = validate_location(form.location.value);
    

    and

    alert("You must enter at least one field:\n\n" + name + specialty + userLocation);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First I want to refer to this post: Where to put Entity Framework Data
First, I want to refer to this post, I think it's the same problem:
I want to refer to the value of an empty text field because I
I have an instance of Class A that I want to refer to in
I am reposting this as my older post was not very clear. I have
I want to download image from internet :: I refer this and try this
I have built an empty associative array whos keynames refer to submitted post data.
I want to refer to a static Java variable in my styles.xml, is that
When I create SQL tables and I want to refer to a membership provider
I want to use rsync to synchronize two directories in both directions. I refer

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.