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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:51:26+00:00 2026-05-26T01:51:26+00:00

I have a C/C++ programming background, and while casually learning Javascript through the @3C

  • 0

I have a C/C++ programming background, and while casually learning Javascript through the @3C webpages on JS, I found this piece of code –

<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Not a valid e-mail address");
  return false;
  }
}
</script>
</head>

<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post">
Email: <input type="text" name="email">
<input type="submit" value="Submit">
</form>
</body>

Well, I do not know if I have missed out any of their previous lessons; am confused over the “return” used in the line –

<form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post">

My question – Since the “onsubmit” in the above line on calling the function “validateForm()” will anyways be looking for a return value of true/false, what is the significance of this explicit return keyword? I see that on deleting the return keyword, and running the above code (as – onsubmit = "validateForm();" ) works, but even if an error in input is there the form ultimately gets submitted after displaying the warning message.

Could you please throw some light on the use of this “return” keyword in this scenario?

Also, I find that there is a lot of deviation in the way Javascript is written, considering my background in c/c++.. am i alone here..? 🙂

thanks!

  • 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-26T01:51:26+00:00Added an answer on May 26, 2026 at 1:51 am

    I believe everyone has nearly answered the question, but then in different ways. Thanks guys.

    I happened to read an excellent article online, which beautifully explains what is actually happening, mostly behind the scenes, using an example that closely resembles the question that I had posted.

    Felt this would turn useful for anyone who might face this issue in the future.

    Link to the article- http://www.quirksmode.org/js/events_early.html
    Read the “Prevent Default” section of the page.

    –arun nair

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

Sidebar

Related Questions

Hey, in a tutorial C++ code, I found this particular piece of confusion: PlasmaTutorial1::PlasmaTutorial1(QObject
I am learning C++ for the first time. I have no previous programming background.
I have a background of programming in Java and C++, so I know all
I have about 4-5 years of background in programming some in C# and some
Quick background: I'm programming in PHP, I have a domain model with a separate
I have been programming using PHP, Javascript and have been a designer for a
I have been using emacs for a while for mainly python programming, and have
I have a legacy code to maintain and while trying to understand the logic
I'm from a Windows programming background when writing tools, but have been programming using
I have a mostly desktop programming background. In my spare time I dabble in

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.