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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:28:39+00:00 2026-06-02T14:28:39+00:00

The validation of the checkbox doesn’t work. It doesn’t give any error. Could you

  • 0

The validation of the checkbox doesn’t work. It doesn’t give any error. Could you please help me to fix it? And how can I combine errors in one alert instead of one by one?

Thanks for any help.

Html code:

<form class="contact_form" action="" method="post" name="contact_form" onsubmit="returnonFormSubmit(this)">
<li>
<label for="First Name">First Name:</label>
<input type="text" name="visitor_name" /><br />
</li>

<li>
<label for="condition">I agree with the terms and conditions.</label>
<input type="checkbox" name="lan" /><br />
</li>

<li>
              <label for="Male">Male:</label>
          <input type="radio" name="gender" value="m" /> &nbsp; Female:<input type="radio" name="gender" value="f" /><br />
              </li>
              <li>
              <label for="National Rating">National Rating:</label>
              <select name="make">
              <option selected>-- SELECT --</option>
              <option> Below 1200 </option>
              <option> 1200 - 1500 </option>
              <option> 1500 - 1800 </option>
              <option> 1800 - 2100 </option>
              <option> Above 2100 </option>
              </select><br />
              </li>

<li>
<button class="submit" type="submit">Submit</button>
</li>
     <div id="error_message" style="color:#ff0000;"></div>

javascript code:

    function onFormSubmit(form_element)
{
    var checked = 0;
    var letters = /^[a-zA-Z]+$/;

if (form_element.visitor_name.value.match(letters))
    {
            true;
            }
    else
            {
    alert("Please enter a valid first name. For example; John.");
    false;
    }
        if (form_element.lan.checked == false)
            {
            alert("Please accept the terms and conditions");
            false;
            }
if (form_element.gender[0].checked == false && form_element.gender[1].checked == false)
    {
    alert("Please select a gender.");
    false;
    }
    if (form_element.make.selectedIndex == 0)
            {
            alert("Please select your rating interval.");
            form_element.make.focus();
            false;
            }
    return true;
}
  • 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-02T14:28:40+00:00Added an answer on June 2, 2026 at 2:28 pm

    You should concatenate the error messages in a variable.

    function onFormSubmit(form_element)
    {
        var checked = 0;
        var letters = /^[a-zA-Z]+$/;
        var errorMessage = "";
        if (!form_element.visitor_name.value.match(letters))
        {
            errorMessage += "Please enter a valid first name. For example; John.\n";
        }
        if (form_element.lan.checked == false)
        {
            errorMessage += "Please accept the terms and conditions\n";
        }
        if (errorMessage != "")
        {
           alert(errorMessage);
           return false;        
        }
        return true;
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple JS form validation does not seem to be working in IE. Any help
How can I get any checkbox from CheckBoxList is selected via jQuery? Markup: <div>
What does the Generate Validation Methods checkbox in the Managed Object Class Generation dialog
I'm trying to setup custom validation for a checkbox. I have 7 checkboxes each
The validation in Eclipse is catching what it deems errors in the framework I've
I run some validation on my form when a checkbox is clicked, which works
I have a HTML checkbox which will perform a simple validation on another textbox,
Since the CheckBox control doesn't increase the checkbox when the font size is increased,
Hi folks would really appreciate your help in answering this rather involved question. Please
i use this javascript syntax for validating a checkbox... alert(document.getElementById(ctl00_ContentPlaceHolder1_Chkreg).checked); if (document.getElementById(ctl00_ContentPlaceHolder1_Chkreg).checked == false)

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.