What about this (untested):

$('textarea').change( function() 
{
        $(this).prepend('Current length:&nbsp;<span id="' + this.id +
'_len">' + this.value.length + '</span>&nbsp;characters');

        $('#' + this.id + '_len').css('color', (( this.value.length >
parseInt( this.id.split()[1] )) ? 'red' : 'green')).html(
this.value.length ) 
}); 


There's probably a chainable way to grab that new span id after the
prepend fcn, but as I said, untested...

m.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Daemach
Sent: Tuesday, January 23, 2007 7:21 AM
To: [email protected]
Subject: Re: [jQuery] Textarea character count


Thanks for the link.

Here's what I came up with:

 $(document).ready(function(){
        
        $('textarea').prepend('Current length:&nbsp;<span id="'+ this.id
+'_len">'+this.value.length+'</span>&nbsp;characters').keypress(
function()
{ 
                $('#'+this.id + '_len').css('color', ((this.value.length
>
parseInt(this.id.split()[1]))?'red':'green')).html(this.value.length)
        } )

 });

<textarea cols="54" rows="5" id="Desc_512"
name="Description">SPORK</textarea>

I'm not sure you can generate a selector dynamically, as I did in the
keypress function.  It seems to be choking on the this.value element as
well. 

It would be really neat if this worked :)  Any advice would be
appreciated. 
I just want to understand how jquery thinks.
-- 
View this message in context:
http://www.nabble.com/Textarea-character-count-tf3062230.html#a8524860
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to