JQuery Character Counter failing in IE8
<p>I've put together the following script to count the characters used in a textarea, for the purposes of sending an SMS. </p>

<p>The code allows for the maximum number of characters sendable by the service provider, and also accounts for special characters (<code>{}^\/|~€\r</code>) taking twice the space as regular ones. This is done by converting each character to its ascii equivalent and comparing it to an array of the values of identified characters. The onscreen text (#remaining, #messages) is then updated to reflect how many characters are being used.</p>

<p>The script works fine in FF and Chrome (latest), and IE9, but fails completely in IE8. It fails in that the onscreen text does not update or change, and no error appears. It simply has no effect.</p>

<p>A secondary issue is that on any browser, the final ascii comparison - 128, the € symbol - does not get picked up. I can type '€' into the text box and the count will only increment by 1, not 2. 128 is the correct value, and is what is generated by the <code>.charCodeAt()</code> function when € is passed to it. All the other symbols increment by 2, as desired.</p>

<p>So: why does this code fail in IE8, and why does the final ascii comparison fail?</p>

<p>All help appreciated.</p>

<pre><code>$('#sms-message').keyup(function(){
    $('#msg-validation').hide();
    var     chars = $(this).val(),
            arr_chars = chars.split(''),
            remaining = $('#remaining'),
            messages = $('#messages'),
            count = 0;

    $.each(arr_chars, function(i, l){
        var     ascii = l.charCodeAt(0),
                arr = [13, 47, 92, 94, 123, 124, 125, 126, 128];

        if($.inArray(ascii, arr) !== -1) { count = count + 2; }
        else { count = count + 1; }
    });

    var     units = Math.ceil(count / 160),
            remaining_chars = 459 - count;

    remaining.text(count + ' characters (' + remaining_chars + ' remaining)');
    messages.text(units + ' text unit(s)');

    if(remaining_chars &lt; 0) {
        $(remaining).css('color', 'red');
    }
    else {
        $(remaining).css('color', 'black');
    }
});
</code></pre>
