jQuery Char Count Variable Issue -


i having @ various methods of using character count in jquery , found 1 , modified , implemented having bit of issue it. wondering if guys give me pointers may going wrong.

this have code:

function countchar(val)  {     var len = val.value.length;      if (len >= 500)     {         val.value = val.value.substring(0, 500);         $('.stat').text(0);     }     else      {         $sv = (500 - len);                 $('.stat').text($sv);         if ($sv <= 20)         {                        $('.stat').css({'border': '1px solid #c33', 'color': '#c33', 'background-color': '#f6cbca'});         }         else if ($sv >= 21 && $sv <= 150)         {             $('.stat').css({'border': '1px solid #9f6000', 'color': '#9f6000', 'background-color': '#feefb3'});         }         else         {             $('.stat').css({'border': '1px solid #090', 'color': '#090', 'background-color': '#dff2bf'});         }      } }  countchar($('#notes').get(0)); $('#notes').keyup(function() {     countchar(this); }); 

my ('#notes') normal textarea.

i have fiddle here:

it based on question found here

when implement on page, wasn't showing up. upon looking @ firebug, giving me following error:

typeerror: val undefined

from understanding, error means need declare using var.

i have done , following error:

typeerror: val.value undefined

i did try doing var on val.value threw syntax error.

i did try using var val in countchar() , gives following error:

syntaxerror: missing formal parameter

i can't seem see missing works in fiddle way to.

any pointers appreciated. in advance.

the issue appears had put outside of document.ready without realising had. works charm now


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -