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

  • Home
  • SEARCH
  • 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 8904211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:04:16+00:00 2026-06-15T02:04:16+00:00

From everything I’ve seen around the net, it appears that the following code should

  • 0

From everything I’ve seen around the net, it appears that the following code should do the following (and this is my expectation):

  • If the email (“aid”) does not match the regex, show alert message and return false
  • If the password (“pass”) is blank, show alert message and return false
  • If both conditions pass validation submit the form

The Javascript is as follows:

function validate() {
var email = document.getElementById('aid').value;
var pass = document.getElementById('apw').value;        
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
if (!emailPattern.test(email)) {
    alert("Not a valid email address");
    return false;
}
if (pass == null || pass == "") {
    alert("Password is blank");
    return false;   
}
return true;
}

The opening for tag is as follows:

<form action="choose.php" onsubmit="validate();" method="post">

The problem I’m having is that when the submit button is clicked, the alert message will pop up, but then choose.php is loaded in the browser. I want the script, if the error conditions are triggered, to remain on the page until both conditions are passed.

  • 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-15T02:04:17+00:00Added an answer on June 15, 2026 at 2:04 am

    You need to change your onSubmit to onSubmit="return validate();". This way when it returns false, the form doesn’t get submitted. Right now it just calls the validate() function and continues on with submitting the form

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From everything I've read, it seemed that adding paging to a ListView control should
Isn't MVC supposed to separate the presentational code from everything else? Wouldn't this make
From everything I've seen, it seems like the convention for escaping html on user-entered
I'm developing a touchscreen application that, aside from everything else, records the amount of
I am creating a php backup script that will dump everything from a database
I need a kind of screenshot from everything that's displayed in an UIView. Maybe
I have configured my Business Application to use Windows Authentication. From everything that I
The following query works: select count(*) from everything where num not in (select num
From everything I've seen on Stack Exchange and elsewhere, I have everything set up
I feel a little silly asking this question, but from everything I've read, this

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.