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

  • Home
  • SEARCH
  • 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 3691124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:06:44+00:00 2026-05-19T04:06:44+00:00

I have the following jQuery code to make my checkboxes act like radio buttons,

  • 0

I have the following jQuery code to make my checkboxes act like radio buttons, so that only 1 of the 3 can be checked at a time.

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    $("#testing input:checkbox").change(function(){
        var checkname = $(this).attr("name");
        $("input:checkbox[name='" + checkname + "']").removeAttr("checked");
        this.checked = true;
    });
});
</script>

The checkboxes are layed out like the following:

<input type="checkbox" id="testing" name="testing" value="B">
<input type="checkbox" id="testing" name="testing" value="I">
<input type="checkbox" id="testing" name="testing" value="A">

This works exactly how i want it to work, not a problem, except once i click one of the 3, i cant unclick it so that none of them are checked, this is what i want to happen, so along with being only able to click one at a time, im able to uncheck them completely.

Any help would be grand 🙂

  • 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-05-19T04:06:45+00:00Added an answer on May 19, 2026 at 4:06 am

    Only run the code that unchecks the others if this has been checked.

    Example: http://jsfiddle.net/CX5Th/1/

    $("#testing input:checkbox").change(function() {
        if( this.checked ) {
            var checkname = $(this).attr("name");
            $("input:checkbox[name='" + checkname + "']").removeAttr("checked");
            this.checked = true;
        }
    });
    

    EDIT: Here’s a revision that prevents the newly checked box from being unchecked when you select the boxes with the same name. It uses not()(docs) to exclude the current checkbox.

    Example: http://jsfiddle.net/CX5Th/2/

    $("#testing input:checkbox").change(function() {
        if (this.checked) {
            var checkname = $(this).attr("name");
            $("input:checkbox[name='" + checkname + "']").not(this).removeAttr("checked");
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following JQuery code which does similar functionality like Stackoverflow where the
i have the following jquery code. basically i will have several overlapped divs and
I am begging to use jquery. I have the following call that works in
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I have the following jquery code which works fine. $('#onlyTwo').click(function() { $(#textarea3).attr(disabled, true); $(#textarea4).attr(disabled,
I'm using the following jquery code to show a contextual delete button only for
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
Recently I have started playing with jQuery, and have been following a couple of
How do you rotate an image using jQuery-rotate plugin? I have tried 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.