PDA

View Full Version : Character count using arrow keys


pthompson2002
08-29-2002, 01:57 PM
Can anyone tell me how I can get a textarea to recognise the arrow keys for an onkeydown event?

I want to get the character position in a textarea returned to the screen and I want it either decrement or increment the count when an arrow key is pressed.

Any ideas?


Cheers Pete

requestcode
08-29-2002, 02:52 PM
This works in IE5+ and NS6+:
<html>
<head>
<title>Test</title>
<SCRIPT language="JavaScript">
IE5=document.all? 1:0
function dispkey(e)
{
whKey = !IE5? e.which:event.keyCode; // check for NS4 and NS6
window.status=whKey // Display ascii code in status bar
}
</SCRIPT>
</head>
<body>
<CENTER>
<FORM NAME="myform">
<TEXTAREA NAME="txta" COLS="30" ROWS="4" WRAP="hard" onKeyDown="dispkey(event)" >Enter your response here</TEXTAREA>
</FORM>
</CENTER>
</body>
</html>

With NS4 it detects most keys except the arrow and delete key. I also found out the the onKeyPress acts differently and will not pass back the ascii value in NS6.