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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:58:31+00:00 2026-05-24T10:58:31+00:00

I have a Jquery toggle function. I have made an if else statment to

  • 0

I have a Jquery toggle function. I have made an if else statment to fix the bug when a checkbox i pressed directly its got checked and uncheched. Therefor I have maded a else if statement to check if the checkbox have been checked. But now the checkbox does not even get checked onclick.

Here it is live: http://jsfiddle.net/mvdnj/14/

My Jquery:

categoryDiv.toggle(function () {
    relativeMinimenu.removeClass('hidediv').addClass('someclass').show(200);
    categoryDiv.addClass('clicked').show(200);

    if(   categoryDiv.find('input:checkbox').attr('checked', 'checked') ) { 
        categoryDiv.find('input:checkbox').attr('checked', false);
    } else{
        categoryDiv.find('input:checkbox').attr('checked', 'checked');
    }
}
, function () {
    categoryDiv.removeClass('clicked').find('input:checkbox').prop("checked", false);
    relativeMinimenu.addClass('hidediv');
});

My HTML:

<div style="margin-top: 81px; width: 200px; float: left; background: none repeat scroll 0% 0% rgb(255, 255, 255);" cxlass="searchbox">  
<form method="get" action="/" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input type="hidden" value="✓" name="utf8"></div>

        <div id="category" class="menuitem category clicked">
                <label id="search_Company1_is_true" for="search_Company1">Company1 </label>
        <input type="hidden" value="0" name="search[Company1_is_true]"><input type="checkbox" value="1" name="search[Company1_is_true]" id="search_Company1_is_true" checked="checked">
        <div class="counter">1</div>
        </div>
        <div id="minimenu" class="someclass">
        <div class="miniitem">
         <label for="search_feature1">feature1</label>
        <input type="hidden" value="0" name="search[feature1_is_true]"><input type="checkbox" value="1" name="search[feature1_is_true]" id="search_feature1_is_true">
        </div>         <div class="miniitem">
         <label for="search_feature1">feature1</label>
        <input type="hidden" value="0" name="search[feature1_is_true]"><input type="checkbox" value="1" name="search[feature1_is_true]" id="search_feature1_is_true">
        </div>         <div class="miniitem">
         <label for="search_feature1">feature1</label>
        <input type="hidden" value="0" name="search[feature1_is_true]"><input type="checkbox" value="1" name="search[feature1_is_true]" id="search_feature1_is_true">
        </div>
        </div>
        <div class="menuitem category clicked">
        <label for="search_company2">company2</label>
        <input type="hidden" value="0" name="search[company2_is_true]"><input type="checkbox" value="1" name="search[company2_is_true]" id="search_company2_is_true" checked="checked">
        <div class="counter">1</div>
        </div>
 <div class="someclass">
        <div class="menuitem">
        </div>
</div>

    <input type="submit" value="Submit" style="display: none;" name="commit" id="search_submit" class="sdasd">

</form></div>
  • 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-24T10:58:33+00:00Added an answer on May 24, 2026 at 10:58 am

    And my suggestion – jsFiddle

    Basically much lighter HTML and jQuery code. I did strip off alot of the CSS, so you could re-add that later.

    HTML

    <form method="get" action="/" accept-charset="UTF-8">
        <div class="checkGroup">
            <label>
                <span>Company1</span>
                <input type="checkbox" name="section" value="1"/>
            </label>
            <div class="payload">
                <label>
                    <span>Feature1</span>
                    <input type="checkbox" name="sub" value="1"/>
                </label>
                <label>
                    <span>Feature2</span>
                    <input type="checkbox" name="sub" value="2"/>
                </label>
                <label>
                    <span>Feature3</span>
                    <input type="checkbox" name="sub" value="3"/>
                </label>
            </div>
        </div>
        <div class="checkGroup">
            <label>
                <span>Company2</span>
                <input type="checkbox" name="section" value="1"/>
            </label>
            <div class="payload">
                <label>
                    <span>Feature1</span>
                    <input type="checkbox" name="sub" value="1"/>
                </label>
                <label>
                    <span>Feature2</span>
                    <input type="checkbox" name="sub" value="2"/>
                </label>
                <label>
                    <span>Feature3</span>
                    <input type="checkbox" name="sub" value="3"/>
                </label>
            </div>
        </div>
    </form>
    

    Javascript / jQuery

    $(document).ready(function(){
    
        $('.payload').hide();
    
        $('.checkGroup > label > input[type="checkbox"]').live('change',function(){
            $t = $(this);
            $t.closest('.checkGroup').find('.payload').toggle( $t.is(':checked') );
            if( !$t.is(':checked') ){
               $t.closest('.checkGroup').find('.payload input[type="checkbox"]')
                   .attr('checked',false);
            }
        }).trigger('change');
    
    });
    

    If you are wanting to have Counters showing how many checkboxes in each group are checked, then use the following Javascript / jQuery – jsFiddle Demo

    $('.payload').hide();
    
    $('.checkGroup > label > input[type="checkbox"]').live('change',function(){
        $t = $(this);
        $t.closest('.checkGroup').find('.payload').toggle( $t.is(':checked') );
        if( !$t.is(':checked') ){
           $t.closest('.checkGroup').find('.payload input[type="checkbox"]')
               .attr('checked',false);
        }
    }).trigger('change');
    
    
    $('.checkGroup input[type="checkbox"]').change(function(){
       $c = $(this);
       $c.closest('.checkGroup').find('label > span b').text( $c.closest('.checkGroup').find('input[type="checkbox"]:checked').length );
    }).trigger('change');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery code, which uses the toggle() function on a checkbox input
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
i have the following jquery code: $(document).ready(function() { $('.restrictiveOptions input[type!=checkbox], .restrictiveOptions select').change(function() { //
I have the following jQuery code which all works fine: $(#sidebar .m3, #sidebar .m5).toggle(function()
I have a problem with this jquery script. toggle:function() { if(this.opened){ $(slideToBuyBottomBtnClosed).setStyle(display,block); $(slideToBuyBottomBtnOpen).setStyle(display,none); $(sildeToBuyContent).setStyle(overflow,hidden);
I have try with toggle function in jquyer but its not working for multiple
I have found this code (jQuery): $('.toggle').click(function() { $('.container').eq($(this).index()).toggle('fast'); }); This is my HTML:
I have some simple jQuery toggle script like this: <script type=text/javascript> $(document).ready(function() { $('#clickedit').click(function()
http://jsfiddle.net/yrM3H/2/ I have the following code: jQuery(document).ready(function() { jQuery(.toggle).next(.hidden).hide(); jQuery(.toggle).click(function() { $('.active').toggleClass('active').next('.hidden').slideToggle(300); $(this).toggleClass('active').next().slideToggle(fast); });

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.