Use .attr('disabled', true) and .attr('disabled', false) to set the
'disabled' state of form elements.

It's one of those things that works in a way you don't quite expect,
if you're thinking of it from an HTML perspective.

After a form element is parsed in from HTML the attributes like
'disabled', 'checked' and 'readonly' become "real" booleans, at least
as far as JavaScript is concerned, so you change them by assigning
true or false.

Hmm I think we're going to need to put this in the FAQ, it gets asked
at least every second week.

Karl Rudd

On Thu, Apr 3, 2008 at 4:21 PM, Gorkfu <[EMAIL PROTECTED]> wrote:
>
>  The setup:
>  2 Radio Buttons and a text field.
>
>  What I wish to accomplish:
>  When Radio #1 is clicked, disable the text box.
>  When Radio #2 is clicked, remove the disabled attribute so the text
>  box is now enabled.
>
>  I also want this done in more than one instance, the "2 Radio Buttons
>  and a text field" will be used on the page more than once, but I want
>  the ids to be unique. So I see using a method where Radio #1 and #2
>  have an id="x1" and the text box has a target="x1". Therefore I can do
>  x2, x3 etc. I'm having problems figuring this one out. Something
>  similar to this was done in HoverTip.
>
>  Below is what I started with, however it doesn't work.
>
>  --- code ---
>
>  $("#Radio2").click(function () {
>         if $(this).is(":checked"))
>                         .next('input').removeAttr('disabled');
>                 else
>                         .next('input').attr('disabled', 'disabled');
>  });
>
>  --- code ---
>

Reply via email to