On Apr 2, 2008, at 4:28 PM, alivemedia wrote:

Still not working, weird, here it is as it stands:

$('input[type=checkbox]').bind("click",function(){
           var el=$(this).parent().next('td select')
           if (this.checked) {
               el.attr('disabled', false);
           } else {
              el.attr('disabled', true);
           }
       }).each(function(){ var el=$(this).parent().next('td select');
       if (this.checked) {
              el.attr('disabled', false);
           } else {
            el.attr('disabled', true);
           }
        });

Ah, yes, but you still didn't change the selector.

Try this (inside document.ready):

        $('input:checkbox').bind("click",function(){
             var el=$(this).parent().next('td').find('select');
             if (this.checked) {
                 el.attr('disabled', false);
             } else {
                el.attr('disabled', true);
             }
        }).each(function(){
           var el=$(this).parent().next('td').find('select');
           if (this.checked) {
                el.attr('disabled', false);
           } else {
            el.attr('disabled', true);
           }
        });

You can also make this a bit more concise if you want:

        $('input:checkbox').bind("click",function(){
           var el=$(this).parent().next('td').find('select');
           el.attr('disabled', this.checked ? false : true);
        }).each(function(){
           var el=$(this).parent().next('td').find('select');
           el.attr('disabled', this.checked ? false : true);
        });

Or, better yet:

        $('input:checkbox').click(disenable).each(disenable);
        function disenable() {
          var el=$(this).parent().next('td').find('select');
          el.attr('disabled', this.checked ? false : true);
        }

If those revisions don't work for you, let me know and I'll post a test page showing it working.

Hope that helps.


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



Reply via email to