6
 function charCount(){
  $.doTimeout('poll', 150, function(){
      messageVal = $('#messageLabel textarea').val();

      messageLength = messageVal.length; //IE BREAKS HERE

      $('#messageLength').html(messageLength + '/140')
      if(messageLength > 140){
          $('#messageLength').not('.inv').addClass('inv')
      }else{
          $('#messageLength.inv').removeClass('inv')
      }
      return false;
  })

}
$('#messageLabel textarea').change(charCount).keyup(charCount);

Gives the following error in Internet Explorer 7.0 (and maybe other versions too).

Object doesn't support this property or method.

Any ideas on what is causing this error?

2
  • 1
    "Nope, not the solution. Thanks" - Try commenting out stuff until the error doesn't appear, and that will isolate the statement that invokes this. Commented Apr 13, 2011 at 10:12
  • @meder You're absolutely right. I already edited the question though. Problem is at line 5 (.length).
    – dubbelj
    Commented Apr 13, 2011 at 10:21

5 Answers 5

23

When you don't use the var keyword, IE browser search for messageLength in the global context and it finds it... you have element with that ID.

Trying to assign number to HTML element fails.

To solve this, just declare messageLength as local variable:

var messageLength = messageVal.length; //IE WON'T BREAK HERE
0

Try yo replace :

messageVal = $('#messageLabel textarea').val();

with

messageVal = $('#messageLabel textarea').text();

Hope it helps.

3
  • Nope, not the solution. Thanks.
    – dubbelj
    Commented Apr 13, 2011 at 10:10
  • try to do a typeof(messageVal)
    – alexl
    Commented Apr 13, 2011 at 10:21
  • strange it must work you sure the error comes from messageVal.length ?
    – alexl
    Commented Apr 13, 2011 at 10:48
0

I think the .change() is having some problem in IE.Please remove it and see if it is working.

Also try using .html() instead of .val().

1
  • Nope, not the solution. Thanks.
    – dubbelj
    Commented Apr 13, 2011 at 10:10
0

look here simple test. textarea does not support value property. you can get it via text property

0

I had a similar error, however, it was because I added the JQuery library to the master page and there was a duplicate library declaration elsewhere the same page.

Not the answer you're looking for? Browse other questions tagged or ask your own question.