473,386 Members | 1,693 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,386 software developers and data experts.

How to invoke javascript event onKeyDown

1
I need to invoke javascript event onKeyDown, which should get invoked when we press any key from anywhere of the page. currently I am callin like this:


Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3. //document.onKeyDown=isBack(event);
  4. function isBack(event)
  5. {
  6.     alert('hit a key');
  7. }
  8. </script>
  9. </head>
  10.  
  11. <body onKeyDown="isBack(event);">
  12.  
  13. <input type="text" id="myid">
  14. </body>
Is ther any way to invoke it, other than from body. Like the line (//document.onKeyDown=isBack(event);) . will it work?
Jul 2 '10 #1
1 2203
Dormilich
8,658 Expert Mod 8TB
Like the line (//document.onKeyDown=isBack(event);) . will it work?
that line will definitely not work (at least not as intended)

you can attach the handler to any element/object you like, but to work global you need it to attach to window or body at least.
Jul 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dennis | last post by:
Hello I am trying to invoke an event from a control manually in c#. Does anyone have any ideas. This is what I have done so far Control b1 = getControl("button1"); EventInfo eventInfos =...
1
by: Matthew Louden | last post by:
I tried the following to invoke javascript in ASP.NET page, but it didnt work. Any ideas?? Response.Write("<script language=""JavaScript"">alert('Hello')</script>")
1
by: AssanKhan Ismail | last post by:
Hi, How to invoke keyPress event in ASP.Net pages instead of performing the same in Client Validation( through Javascript) can i do it in server side ? Thanks in advance. bye assankhan
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.