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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:10:05+00:00 2026-06-13T04:10:05+00:00

How i put validation on check box? Here is my code: <script> function Validate(){

  • 0

How i put validation on check box?

Here is my code:

<script>
function Validate(){
   var cntct = document.getElementById("contact").value;
   if (cntct.value=="")
   {
      alert("Please select contact medium");
      return false;
   }
}
</script>

<input type="radio" name="contact" id="contact" value="SMS">
<label>SMS</label> <input type="radio" name="contact" id="contact" value="CALL">
<label>CALL</label> <input type="radio" name="contact" id="contact" value="EMAIL">
<label>EMAIL</label>

please help..

  • 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-13T04:10:06+00:00Added an answer on June 13, 2026 at 4:10 am

    in case of checkboxes and radiobuttons, the element is checked when the “checked” property is true:

    function Validate(){
        var selectedValue = "";
        var cntct = document.getElementsByname("contact");
        for(var i=0;i<cntct.length;i++) {
            if (cntct[i].checked)
            {
                selectedValue = cntct.value;
            }
        }
        if(selectedValue == "") {
            alert("Please select contact medium");
            return false;
        }
        return true;
    }
    

    UPDATE

    I just noticed that you have multiple elements with the same ID. This is not allowed, in such case the browser will return only the last element with that ID. You need to iterate over the elements with the same name and pick one with attribute checked. See the code above

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

Sidebar

Related Questions

I have the following code... var min_val = [{id:driverDOA,value:date_of_accident},etc etc...];//put validation elements in an
Am trying to put together a form validation script, and i hit a snag
I have a big validation JS script. I want to put this script to
i'm trying to put together some Javascript form validation to check that all fields
I want to put a validation that the user always enters a value in
iPhone forms, where do you put your validation? People suggested me to directly put
How can I put disable the cause validation property of a control while the
Put value as a field makes sense only if this one represents some object's
I have 3 textboxes and I want to check if put together they all
Using various tutorials namely here and here I've managed to put together the following

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.