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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:49:05+00:00 2026-06-03T12:49:05+00:00

I am having trouble checking whether there is a radio selection is not made

  • 0

I am having trouble checking whether there is a radio selection is not made in my form. In my form, I have 5 items, each item is given 2 options (radio buttons). Something like this:

item 1    opt1   opt2   (name attribute is "1")
item 2    opt1   opt2   (name attribute is "2")
item 3    opt1   opt2
item 4    opt1   opt2
item 5    opt1   opt2

I have given all input radio buttons the same class name as items are generated dynamically, so are the name attribute of the input. Here is my code of check each item:

$(document).ready(
    function(){
        $('#submit').click(function(){
                var buttons = document.getElementsByClassName('radio_class');
                var radio_num = buttons.length; //which returns 10 in this case
                var error = "";
                for (var i=0; i<radio_num; i=i+2){
                    var radio_name = buttons[i].getAttribute("name");
                    if (!$("input[@name=radio_name]:checked").val()) {
                        error += radio_name + " ";
                    }
                }
                if (error !== "") {
                    alert (error+"not checked!");
                    return false;
                }
                else {
                    alert ("All the items have been checked.")
                }
            }
        );
    }
);

If all the five items are not checked, it alerts the correct message that is “1 2 3 4 5 not checked”, however, if I just check one item, the message “All the items have been checked.” will be alerted. Can anyone help me with this? 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-06-03T12:49:10+00:00Added an answer on June 3, 2026 at 12:49 pm

    where you wrote

    if (!$("input[@name=radio_name]:checked").val()) {
        error += radio_name + " ";
    }
    

    try instead

    if (!$("input[name='"+radio_name+"']:checked").val()) {
        error += radio_name + " ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble checking out a project via svn. I have a repository set
Thanks for checking out my problem... I'm having trouble submitting a login form via
I have been having trouble getting the screen dimensions for android. I do not
I am having trouble checking checkboxes via JQuery - I have done this: if(element[1]==3)
As title says, im having trouble with my junit tests passing for checking if
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I'm having trouble checking in PHP if a value is is any of the
I'm having trouble checking hidden checkboxes in IE. This is the base html: <input
With WebDriver from Selenium 2.0a2 I am having trouble checking if an element is
I'm having trouble with the submit() function. I need to submit a form after

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.