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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:22:09+00:00 2026-06-02T04:22:09+00:00

I have few checkboxes on a page with name and id = selectArticle[]. What

  • 0

I have few checkboxes on a page with name and id = selectArticle[]. What I need is that whenever user checks the checkbox, certain elements should get class=”required” attached to it and when I uncheck the same box, the class=”required” should be deleted.

I have tried .addClass and .removeClass, however whenever i uncheck the checkbox the .remove effect never takes place. However when i Check the checkbox again(in case of .toggleClass), the class toggles perfectly. It seems like it works only on the checkbox ‘checked’ event and not unchecked.

Through alert, I have checked, both the check/uncheck events are fired perfectly yet the .removeClass/.toggleClass doesnt work at all.

How do I rectify this problem. Please help me out!!!

       $("input[name='selectArticle[]']:checkbox").live('change',function(){
          var n = $("input[name='selectArticle[]']:checked").length;
          var id=$(this).val();
          var v = $(this).is(':checked');
          //var vr= $("input[name='selectArticle[]']:unchecked").val();
          //var vr= $(this).val();
          alert(v);
          alert(id);
          //alert("url"+v);
          if($(this).is(':checked'))
          {

            alert('#url'+v);
            $("#title"+id).toggleClass('required');
            $("#id"+id).toggleClass('required');
            $("#url"+id).toggleClass('required url');
            $("#category"+id).toggleClass('required');
            $("#group"+id).toggleClass('required');
          }
          else
          {
            alert("balls"+id);
            ("#title"+id).toggleClass('required');
            $("#id"+id).toggleClass('required');
            $("#url"+id).toggleClass('required url');
            $("#category"+id).toggleClass('required');
            $("#group"+id).toggleClass('required');
          }
         // $("div").text(n + (n <= 1 ? " is" : " are") + " checked!" + " value :" + v);
    });

UPDATE: The answer below

    $("input[name='selectArticle[]']:checkbox").live('change',function(){
          var n = $("input[name='selectArticle[]']:checked").length;
          var id=$(this).val();
          var v = $(this).is(':checked');
          //var vr= $("input[name='selectArticle[]']:unchecked").val();
          //var vr= $(this).val();
          alert(v);
          alert(id);
          //alert("url"+v);
          if($(this).is(':checked'))
          {

            alert('#url'+v);
            $("#title"+id).addClass('required');
            $("#id"+id).addClass('required');
            $("#url"+id).addClass('required url');
            $("#category"+id).addClass('required');
            $("#group"+id).addClass('required');
          }

         if(!$(this).is(':checked'))
          {
            alert("balls"+id);
            $("#title"+id).removeClass('required');
            $("#id"+id).removeClass('required');
            $("#url"+id).removeClass('required url');
            $("#category"+id).removeClass('required');
            $("#group"+id).removeClass('required');
          }
         // $("div").text(n + (n <= 1 ? " is" : " are") + " checked!" + " value :" + v);
    });
  • 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-02T04:22:11+00:00Added an answer on June 2, 2026 at 4:22 am

    As because toggleClass is not working try

    if($(this).is(':checked'))
    {
        $("#title"+id).removeClass('required');
        ...
    }
    else
    {
        $("#title"+id).addClass('required');
        ...
    }
    

    Make sure your var id=$(this).val(); contains something valid because ("#title"+id), $("#id"+id) and others using same variable.

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

Sidebar

Related Questions

i have an app that has a few checkboxes in the settings and then
I have a view with a few checkboxes that can be selected or unselected.
I have a few checkboxes that submit and change an attribute's value on my
Here's the scenario: I have a contact form with few checkboxes: <input type=text name=cola[]
I have a few checkboxes in my form and I need to change their
I have a few checkboxes coming from nested model ( :admin accepts_nested_attributes_for :account_setting ).
I have a list a simple dialog box which contains a few checkboxes, I
i have form in drupal which uploads images and has got few checkboxes in
I have a set of checkboxes and have disabled few which I want to
I have few tabs and I need to way to access textboxes on them

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.