by Kevin Schroeder | 12:00 am

I was recently informed of a bug in my turing test for comments on my site.  It turned out that there was a problem that the bit addition scheme when working with IE. Since about 4% of my visitors are IE users it never really came up; until it did. 🙂

Anyways, the way I was doing the test before was with  some basic bit shifting done in JavaScript like this

function mdfyBits(box)
{    
    el = document.getElementsByName("bits[]");
    
    val = 0;
    for (i in el) {
        if (el[i].checked) {
            alert(el[i]);
            val += 1 << el[i].value;
        }
    }
    
    $("#turing").val(val);
    
    alert($("#turing").val());
}

Even running IE in compatibility mode didn't fix it.  Turns out that I guess IE doesn't like that.  So I looked for a JQuery replacement and this is what I changed it to.

function mdfyBits(box)
{
    el = $("input[name=bits[]]");
    
    val = 0;
    for (i in el) {
        if (el[i].checked) {
            val += 1 << el[i].value;
        }
    }
    
    $("#turing").val(val);
}

Works now.  Dang browser compatibility.

Tags:

Comments

Web Design Company India

Hey, thanks for this code, actually I was looking for it.

Feb 13.2013 | 03:10 am

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.