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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:47:45+00:00 2026-06-01T18:47:45+00:00

I have been requested to create a simple form with JavaScript validation code. I

  • 0

I have been requested to create a simple form with JavaScript validation code. I have constructed the entire form and all of my validation scripting is working, however I have been asked to display any relevant errors in Span tags next to the appropriate field (as opposed to displaying alerts as I am used to doing).

I have been told to have a span tag next to each element like text input, radio button etc with the appropriate error text previously entered, and then style each span so that they are hidden. When the submit button is pressed, the script is supposed to change the style of the appropriate span to visible in order to display the text. I have written the code for this but the issue I am having is that my Span errors become visible, but almost instantly they disappear back to the hidden state. Is there any particular reason this could be happening?

Here’s some of my code.

HTML:

< input type="checkbox" name="agree"/> < span id="agreeSpan>Error text< /span>

CSS:

span {
color:red;
font-size:small;
visibility:hidden;
}

And the JavaScript:

   function validateAgreement()
    {

    var agreeBox = document.registration.agree;
    var agreeSpan = document.getElementById('agreeSpan');

   if (!agreeBox.checked) {
      agreeSpan.style.visibility = 'visible';
      return false;
    }

Am I missing something obvious? Is it possible that I am trying to style 1 specific span and that the styling attribute for the general span tags is overriding this particular one?

Thanks very much and apologies if this is a rookie question! I’m new to JS 🙂

  • 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-01T18:47:47+00:00Added an answer on June 1, 2026 at 6:47 pm

    To stop the submit happening, returning false there is not enough. It depends how you’re calling that function, which I imagine is something like this

    <form action='blah' onsubmit='return validateAgreement();'>
     ...
    </form>
    

    Note the return. The on submit handler needs to be returning false, so you need to make sure to return whatever value your function returns. If you just did…

    <form action='blah' onsubmit='validateAgreement();'>
     ...
    </form>
    

    then your form will always get submitted.

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

Sidebar

Related Questions

I have a simple form in my MVC3 site that allows users to create
I have been trying to create a fairly simple application in WPF following the
I have been using the following code to obtain a simple web response from
We have been requested to stream a single video (+500MB) from a web site.
Have been working on this question for a couple hours and have come close
I have a very simple form where users can enter their email and click
So .... There are obviously many questions that all have been asked about Singletons,
I have a very simple contact form on my site, Im looking for users
I have a simple subscribe form at : http://thepanamainsider.com/sanblas/index9.php The form doesn't work, it
I have what I think is a simple problem but have been unable to

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.