Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By droctoganapus86
  • 1 Post By misson

Thread: jquery UI & jQuery

  1. #1
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member
    Join Date
    Nov 2010
    Posts
    49

    jquery UI & jQuery

    Hello, i have a slight problem with the jqury UI and some jquery code.
    i have a couple of checkboxes, i want that when you click the first checkbox, the others are unchecked, and vica verca. I have this html :
    HTML Code:
    <div class="buttonset">
    	<input name="all" id="all" type="checkbox" checked="checked" /><label for="all" title="All">All</label>
    	<input name="audio" id="audio" type="checkbox" /><label for="audio" title="Audio">Audio</label>
    	<input name="video" id="video" type="checkbox" /><label for="video" title="Video">Video</label>
    	<input name="apps" id="apps" type="checkbox" /><label for="apps" title="Programma's">Apps</label>
    </div>
    and this piece of jquery:
    Code:
    $(function(){
    	$('.pirate input[type="checkbox"]#all').click(function(){
    		$('.pirate input[type="checkbox"]:not(#all)').attr('checked', false);
    	});
    	$('.pirate input[type="checkbox"]:not(#all)').click(function(){
    		$('.pirate input[type="checkbox"]#all').attr('checked', false);
    	});
    });
    this works fine, but when i call
    Code:
    $('.buttonset').buttonset();
    it suddenly stops working. any ideas how to fix this?
    Last edited by droctoganapus86; 06-26-2011 at 10:18 AM.
    dinomirt96 likes this.

  2. #2
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: jquery UI & jQuery

    What does the error console say? "It suddenly stops working" tells us almost nothing. When asking for help, describe what you expect to happen and what actually happens, including any error messages.

    Did you include the jQuery UI script? Does it have the Button widget?
    karimirt47 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    8,282

    Re: jquery UI & jQuery

    Quote Originally Posted by droctoganapus86 View Post
    HTML Code:
    <div class="buttonset">
    	<input name="all" id="all" type="checkbox" checked="checked" /><label for="all" title="All">All</label>
    	<input name="audio" id="audio" type="checkbox" /><label for="audio" title="Audio">Audio</label>
    	<input name="video" id="video" type="checkbox" /><label for="video" title="Video">Video</label>
    	<input name="apps" id="apps" type="checkbox" /><label for="apps" title="Programma's">Apps</label>
    </div>
    
    <!-- ADD A BUTTON TO TEST THE ACTUAL STATES -->
    
    <button name="test" id="test" />TEST</button>
    and this piece of jquery:
    Code:
    $(function(){
    	$('.pirate input[type="checkbox"]#all').click(function(){
    		$('.pirate input[type="checkbox"]:not(#all)').attr('checked', false);
    	});
    	$('.pirate input[type="checkbox"]:not(#all)').click(function(){
    		$('.pirate input[type="checkbox"]#all').attr('checked', false);
    	});
            // HOOK BUTTON TO CODE THAT SHOWS REAL STATE OF CHECKBOXES
            $("#test").click( function(){
                  var mess =;
                  var mess = "Boxes: "  + "all: " + jQuery("#all").attr('checked' ) + 
                    "\n audio: "  + jQuery("#audio").attr('checked' ) +
                   "\n video: "  + jQuery("#video").attr('checked' ) +
                    "\n apps: "   + jQuery("#apps").attr('checked' ) ;
                   alert( mess ) ;
            });
    });
    Learn how to debug. Test to see what is going on.

    You will find out that the underlying checkboxes are operating correctly. The jQuery display just does not reflect the programatically induced change. It is not automatic.

    Look at the documentation:

    http://jqueryui.com/demos/button/

    Look the the methods available to buttons.

    You want to refresh the display. Amazing!!!

    There is a method called "refresh" which the docs say:

    Refreshes the visual state of the button. Useful for updating button state after the native element's checked or disabled state is changed programatically.
    Sounds like what you want.

    So, adjust your click handler to update the display of all the buttons. Since you grouped them with buttonset, try:

    Code:
    $(function(){
    	$('.pirate input[type="checkbox"]#all').click(function(){
    		$('.pirate input[type="checkbox"]:not(#all)').attr('checked', false);
                    $('.buttonset').buttonset().refresh() ; // REFRESH DISPLAY
    	});
    	$('.pirate input[type="checkbox"]:not(#all)').click(function(){
    		$('.pirate input[type="checkbox"]#all').attr('checked', false);
                    $('.buttonset').buttonset().refresh() ; // REFRESH DISPLAY
    	});
    });
    And miracle! It works! (at least on my test page).

    P.S. A selector like $('.pirate input[type="checkbox"]#all') is horribly obscure and inefficient. ID's should be unique, so that can be replaced by $('#all')
    Last edited by descalzo; 06-26-2011 at 06:28 PM.
    Nothing is always absolutely so.

  4. #4
    droctoganapus86's Avatar
    droctoganapus86 is offline x10Hosting Member
    Join Date
    Nov 2010
    Posts
    49

    Re: jquery UI & jQuery

    ok, my question wasn't as smart as i thought. but my problem is fixed now, thanks to descalzo.

  5. #5
    vekou's Avatar
    vekou is offline x10 Sophmore
    Join Date
    Mar 2008
    Posts
    167

    Re: jquery UI & jQuery

    Quote Originally Posted by descalzo View Post
    P.S. A selector like $('.pirate input[type="checkbox"]#all') is horribly obscure and inefficient. ID's should be unique, so that can be replaced by $('#all')
    Agreed. It also makes the code shorter, thus smaller file size, thus faster page loads.
    We hate people who solicit reputation using their signatures. Click if you agree.

Similar Threads

  1. PHP, Jquery and cookies
    By tommieonos84 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 8
    Last Post: 06-28-2011, 03:50 PM
  2. drupal and jQuery
    By ganjasensation0098 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 2
    Last Post: 04-15-2011, 09:32 AM
  3. jQuery .each()
    By pratham.gharat200395 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 7
    Last Post: 02-10-2011, 08:12 AM
  4. jquery help
    By bioshock in forum Scripts, 3rd Party Apps, and Programming
    Replies: 0
    Last Post: 10-28-2010, 08:47 AM
  5. jQuery & CSS Help...
    By toddart65 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 7
    Last Post: 05-16-2010, 10:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers