SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE bug for disabling form controls?

    I would like to implement a checkbox within a form that when checked will enable a certain dropdown list element. When the checkbox is unchecked, the element will become disabled (and grayed out).

    I do this by using the following code from within the checkbox onchange-handler:
    Code:
    var obj = document.getElementById('id_dropdown');
    var chk = document.getElementById('id_checkbox');
    if (obj && chk) obj.disabled = !chk.checked;
    This works just fine in Opera, Mozilla and Firebird. However, IE 6 seems to have a bug. The control is not disabled (nor grayed) until either the control is clicked or I click somehwere else on the form.

    This is very aggravating indeed...

    Is this a known bug? If so, then is there a workaround I can use?

    (Hint: I've tried doing a setTimeout for a delayed disable, but this does not help either).
    Last edited by kgish; Jan 8, 2004 at 01:23. Reason: Fixed typos
    Kiffin
    Your average future-famous kind of guy...

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll assume those are typos in your post ('disable', two 'obj').
    Code:
    <form>
    <input type="checkbox" onclick="whatever.disabled=!this.checked">
    <select name="whatever" disabled="disabled">
    .......
    .......
    </select>
    </form>
    ::: certified wild guess :::

  3. #3
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about the typos, but I fixed them.

    Still my problem stands, e.g. had nothing to do with the typos.

    Anyone out there who is familiar with this problem?
    Kiffin
    Your average future-famous kind of guy...

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone out there who is familiar with this problem?
    Yeah - me. You're using onchange instead of onclick. A change event is supposed to fire when an element has been altered, and then loses focus...although the last may vary from platform to platform. That's why you should use onclick whenever feasible.

    The code I posted was shorter and more sensible. Did you bother trying it?
    ::: certified wild guess :::

  5. #5
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, you are absolutely right. I made the changes to use onclick, and everything works fine now. Thanks!
    Kiffin
    Your average future-famous kind of guy...

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Far out.
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •