Hi Howard,

Looks cool! Here is what I came up with (untested), starting with any 'tr' that contains a checkbox and going from there. I'm not sure what you're asking about the ID, so I didn't put that part in here. Are you going to use the id for something else later on?

Anyway, hope this helps you refine your code.

$('tr[input:checkbox]').click(function() {
  var $toggleTicket = $(this).find('[EMAIL PROTECTED]');
  if ($toggleTicket.is(':checked')) {
    $toggleTicket.removeAttr('checked');
  } else {
    $toggleTicket.attr('checked', 'checked');
  }
});



--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Apr 18, 2007, at 10:03 AM, Howard Jones wrote:


Having just made my first real piece of jQuery code, I'm already
wondering if it can be made more concise   :-)

It's an unobtrusive mod to an existing page (in Best Practical's RT
ticketing system). The page has a table of ticket entries, where of the
TDs in each row is a checkbox. I want to be able to click anywhere on
the row to toggle the checkbox.

This is my currently working version. Can I attach an event to the
parent's parent, but have the matching checkbox's ID passed to it, in
one chain?

$('input:[EMAIL PROTECTED]').each(
    function() {
         var myid = $(this).attr('name');
         $(this).parent().parent().click( function(event) {
             if(event.originalTarget.tagName != 'INPUT')
             {
                 var cb = $('input:[EMAIL PROTECTED]'+myid+']');
                 cb.attr('checked', !cb.attr('checked'));
                 return false;
             }
        });
    });

Thanks for any pointers - I'm enjoying adding functionality to RT this
morning. The ContextMenu plugin has also made an appearance in another spot.

Cheers,

Howie



Reply via email to