Here is a little extension I wrote for jquery to do disabling:

jQuery.fn.extend({
 filterHasDisabled : function(){ return this.filter(function(){return
(typeof(this.disabled)!=undefined)})},
 disabled: function(h) {
        if (h!=undefined) return
this.filterHasDisabled().each(function(){this.disabled=h});
        this.filterHasDisabled().each(function() {h=((h||
this.disabled)&&this.disabled)}); return h;
 },
 toggleDisabled: function() { return
this.filterHasDisabled().each(function(){this.disabled=!
this.disabled});}
});

So, with the piece of code above, you can do the following:

$("#button").disabled(true);
or use it with multiple objects:
$(".button").disabled(true);
or just toggle states
$(".button").toggleDisabled();
or get the state of a control
if ($("#button").disabled()) { /*we are disabled*/}
(if multiple objects, then it returns the ANDed value - all must be
disabled for true)

This will also chain like other calls:
$(".button").disabled(true).val("disabled!");



On Sep 24, 3:17 pm, sheetzam <[EMAIL PROTECTED]> wrote:
> Using jquery 1.2.1toggle:
>
> jQuery().ready(function(){
> $('#multiple').toggle(
>         function(){
>                 $('.afield').attr('disabled',true);
>                 },
>         function(){
>                 $('.afield').removeAttr('disabled');
>                 }
>         );
>
> });
>
> I'm trying totogglethe disabled attribute of some text input boxes
> based on acheckboxinput:
>
> <form>
>  <input id="multiple" type="checkbox">TheToggle</input>
>  <input type="text" class="afield">
> </form>
>
> However, when thecheckboxis clicked, the check does not appear.
> Fails in IE and Firefox.
>
> I've tried adding code to check the box, but that fails as well.
> jQuery().ready(function(){
> $('#multiple').toggle(
>         function(){
>                 $('#multiple').attr('checked',true);
>                 $('.afield').attr('disabled',true);
>                 },
>         function(){
>                 $('#same').removeAttr('checked');
>                 $('.afield').removeAttr('disabled');
>                 }
>         );
>
> });
>
> What's the best way to accomplish disabling text inputs with acheckbox?  Am I 
> overthinking this?
>
> Any help would sure be appreciated.

Reply via email to