SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Firefox Bug?

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Location
    Leeds, UK
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Firefox Bug?

    Hi,

    I've been running the following code in W3Schools' "Try It" javascript editor and I can't understand why it'll work in Safari but not Firefox (these are the only 2 I've tested so far):

    Code:
    <html>
    <head>
    
    </head>
    
    <body>
    
    <input type="checkbox" id="myCheckbox" />
    
    <script type="text/javascript">
    var box = document.getElementById("myCheckbox");
    
    function test() {
        if(box.disabled) {
            box.disabled = false;
            box.click();
        } else {
            box.click();
            box.disabled = true;
        }
    }
    </script>
    
    <input type="button" onclick="test()" value="Do It" />
    
    </body>
    </html>
    What should happen is when the user clicks the "Do It" button, the checkbox will become disabled and checked. If the button is clicked again, the checkbox will revert back to normal. Safari handles this just fine but Firefox will leave the checkbox ticked after the second click.

    Anyone else noticed this weirdness?

    I realise that visually, I could use "box.checked" to show and hide the tick but in the scenario i'd like to use this code in, I need the checkbox's onClick action to run.

    Andy

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that does seem to be a bug, kind of a timing issue as this code works:
    Code:
    function test() {
        if (box.disabled) {
            box.disabled = "";
            window.setTimeout(function () {document.getElementById("myCheckbox").click();}, 10);
        } else {
            box.click();
            box.disabled = "disabled";
        }
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Location
    Leeds, UK
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jim,

    Yeah that one works fine, thank you. Annoying bug though!

    Cheers,

    Andy


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
  •