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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:21:39+00:00 2026-06-03T20:21:39+00:00

The javascript: function validateForm() { var x=document.forms[newsletter][agree].value; if (newsletter.agree.checked != 1) { alert(Checkbox must

  • 0

The javascript:

    function validateForm()
{
    var x=document.forms["newsletter"]["agree"].value;
    if (newsletter.agree.checked != 1)
    {
        alert("Checkbox must be checked");
        return false;
    }


    var y=document.forms["newsletter"]["email"].value;
    var atpos=y.indexOf("@");
    var dotpos=y.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=y.length)
    {
      alert("Not a valid e-mail address");
      return false;   
    }

    else 
    {   
        return true;
    }
}

And my HTML

<div id="signup">
<form id="newsletter" action="" method="get" onsubmit="return validateForm()">
<fieldset>
<p>Email: <input type="text" name="email" size="35"/>
Please send me the monthly newsletter 
<input type="checkbox" checked="checked" name="agree" value=""/>
<br/>
<input type="submit" value="Signup"/></p>
</fieldset>
</form>
</div><!-- signup -->

When I click submit with invalid entries in Chrome, the alert messages show and the form doesn’t submit. However, when I do the same in Firefox, the form submits without an alert message.

I’ve been working on this for 5 hours, I truly have no idea. Thanks for any help, it’s greatly 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-06-03T20:21:41+00:00Added an answer on June 3, 2026 at 8:21 pm

    I think it might help you.

    <div id="signup">
            <form id="newsletter" action="" method="get" onsubmit="return validateForm()">
            <fieldset>
            <p>Email: <input type="text" name="email" id="email" size="35"/>
            Please send me the monthly newsletter 
            <input type="checkbox" checked="checked" name="agree" id="agree" value=""/>
            <br/>
            <input type="submit" value="Signup"/></p>
            </fieldset>
            </form>
            </div><!-- signup -->
    
    
    
       function validateForm()
        {
            var agreeEl = document.getElementById("agree");
            if (agreeEl.checked != 1)
            {
                alert("Checkbox must be checked");
                return false;
            }
    
    
            var emailEl = document.getElementById("email");
            var atpos = emailEl.value.indexOf("@");
            var dotpos = emailEl.value.lastIndexOf(".");
            if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= y.length) {
              alert("Not a valid e-mail address");
            return false;   
            }
    
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty straight-forward javascript form validation script written: function validateForm(){ var x=document.forms[contactForm][firstname].value;
Using the javascript function function squareIt(number) { return number * number; } When given
I have a JavaScript function code where I want to alert. function msgalert(x,y) {
I have a JavaScript function code where I want to alert. function msg(x,y) {
How do i introduce validation before remote_form_for submits? I have javascript function called validateForm()
I need help with javascript. here is my problem: <script type=text/javascript> function validateForm() {
Javascript function does not work when function loadcontents(obj) { var params = $(obj).attr('href').split('?'); $.getJSON(IVIDPLAY_BASE_DIR+'content/load2.php?'+params[1],
So in default.aspx I have the code <script type=text/javascript> function validateForm() { test(); //here
My Javascript function aa() is called with the value of the paying_now input field.
I need a javascript function which gets a string and returns false if the

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.