473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Capture keypress inside a textarea

How do I capture the keycode inside a <textarea> in NN6+ and IE5.5+? I don't
want to add add document.keyPress function because I only want this to
occure when a specific textarea is selected and not fire for every keypress
in the entire document.

<textarea onkeypress="captureKeys();"....

but I cannot get a reference to the current event so i can ask for the
keyCode. In IE I can check the event.keyCode inside my function captureKeys
but this is not possible in NN6+.

Regards
/Stefan
Jul 23 '05 #1
1 18553


Hans wrote:

<textarea onkeypress="captureKeys();"....

but I cannot get a reference to the current event so i can ask for the
keyCode. In IE I can check the event.keyCode inside my function captureKeys
but this is not possible in NN6+.


Simply use
<textarea onkeypress="return captureKeys(event);"
and then
function captureKeys (evt) {
var keyCode = evt.keyCode ? evt.keyCode :
evt.charCode ? evt.charCode : evt.which;
if (keyCode == ...) {
// cancel key:
if (evt.preventDefault) {
evt.preventDefault();
}
return false;
}
return true;
}

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: George Hester | last post by:
When the address bar is highligted? That is nothing on the page is selected. The address bar is selected. Capture keydown or keypress? Any ideas using javascript? Thanks. -- George Hester...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
7
by: Bob Achgill | last post by:
When I use the code for KeyPress to capture pressing a certain key for processing on a form with no Text Box it works. But when I try the same code on my application that has text boxes it does...
1
by: Jan Doggen | last post by:
Hello all, I have a SELECT like this (the 'alert()s are temporary): <FORM method="POST" action="/scripts/runisa.dll?OVB2.132964:PGSPLITVACAFMELDEN:1095144287.9159" id="hulpform"...
4
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
I know how to capture a keypress for a windows application, but how would I go about doing it for a windows service? Rather than having a form in focus all the time, I would prefer to have...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.