PDA

View Full Version : Turn textarea font red after 120 characters have been inserted..


kilbad
10-23-2007, 01:35 PM
I want to turn a textarea font red (as the person is actually typing in the box) after 120 characters have been inserted, but go back to a black font color if they were to delete back to less than 120. Can someone help me get started with this idea? I am guessing javascript will probabaly be required.

Thanks in advance!
k

RysChwith
10-23-2007, 04:32 PM
<textarea onchange = "this.style.color = ( this.value.length > 120 ) ? '#f00' : '#000'"></textareaThat ought to do it.

Rys

coothead
10-23-2007, 04:53 PM
Hi there Rys,

I would , humbly ;), suggest that onkeyup would be a better choice than onchange.

RysChwith
10-24-2007, 08:29 AM
Oh, right. Onchange only fires when the element loses focus. Good catch.

Rys