Here is a little extension I wrote for jquery to do disabling:
jQuery.fn.extend({
filterDisabled : function(){ return this.filter(function(){return
(typeof(this.disabled)!=undefined)})},
disabled: function(h) {
if (h!=undefined) return
this.filterDisabled().each(function(){this.disabled=h});
this.filterDisabled().each(function()
{h=((h||this.disabled)&&this.disabled)}); return h;
},
toggleDisabled: function() { return
this.filterDisabled().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!");
sheetzam wrote:
>
>
> Using jquery 1.2.1 toggle:
>
> jQuery().ready(function(){
> $('#multiple').toggle(
> function(){
> $('.afield').attr('disabled',true);
> },
> function(){
> $('.afield').removeAttr('disabled');
> }
> );
> });
>
> I'm trying to toggle the disabled attribute of some text input boxes
> based on a checkbox input:
>
> <form>
> <input id="multiple" type="checkbox">The Toggle</input>
> <input type="text" class="afield">
> </form>
>
> However, when the checkbox is 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 a
> checkbox? Am I overthinking this?
>
> Any help would sure be appreciated.
>
>
>
--
View this message in context:
http://www.nabble.com/toggle-and-checkbox-tf4512435s15494.html#a12947063
Sent from the JQuery mailing list archive at Nabble.com.