I get a lot of funny messages sent to me on Where's Tim. I keep them all and put them on this page. Sometimes, people have so much to say that their message exceeds the 160 character message limit for my phone. So I wrote a function that tells people how many characters until the end of the message.
The countChar function takes a textbox object and a div object. The div object will display how many characters are left.
function countChar(txtBox,messageDiv)
{
try
{
count = txtBox.value.length;
if (count < 160)
{
charLeft = 160 - count;
txt = charLeft + " characters left...keep typing!!";
messageDiv.innerHTML="<font color=green>" + txt + "</font>";
}
else
{
messageDiv.innerHTML="<font color=red>Message is too long</font>";
}
}
catch ( e )
{
}
}
|
I can then call that function from the onkeyup event of my textbox like this:
<INPUT type="text" id="txtMessage"
onkeyup="countChar(txtMessage,messagesuccess);"
onkeydown="if(event.keyCode == 13){document.getElementById('btnSendTextMessage').click();}" >
|