473,765 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Respond to keypresses on top of a paragraph

I am having trouble responding writing a Javascript Program respond
to keypresses on top of a paragraph. Here is the code I tried:

<HTML>
<SCRIPT Language="JavaS cript">
document.write( "TEeve");
function QQ(event){
alert("Key Pressed " + event.charCode( ));
}

</SCRIPT>

<P onkeypress="QQ( event)">Testing </P>

The alert is not displayed when I click on the paragraph and press
ordinary
keys.

By the way the following related Javascript to respond to mouse events
on a
paragraph does work.

<HTML>
<SCRIPT Language="JavaS cript">
document.write( "Tex");
function QQ(event){
alert("Displayi ng Mouse Coordiantes "+event.cli entX
+","+event.clie ntY);
}

</SCRIPT>
<body>
<P onmousedown="QQ (event)">Testin g</P>
</body>
</html>

Thus, what don't I understand about the keypressed event?
I am running Mozilla 5.0 (rv:1.7.10 Geck/200507

I also tried someother options suggested by the W3C Level Tw Events
Specification.

But section 1.6.3 said that "the DOM Level 2 Event specification does
not provid
a key event module."
Dr. Leff, Western Illinois University FAX 309 298 2302 Pager 309 367
0787
Associate Professor of Computer Science, One University Circle, Macomb
IL 61455

Apr 14 '07 #1
1 1725
wrote on 14 apr 2007 in comp.lang.javas cript:
I am having trouble responding writing a Javascript Program respond
to keypresses on top of a paragraph. Here is the code I tried:

<HTML>
<SCRIPT Language="JavaS cript">
document.write( "TEeve");
function QQ(event){
alert("Key Pressed " + event.charCode( ));
}

</SCRIPT>

<P onkeypress="QQ( event)">Testing </P>

The alert is not displayed when I click on the paragraph and press
ordinary keys.
You cannot key anything on an element that cannot receive KEY presses.
Such element is not even "on focus" for the keyboard.
By the way the following related Javascript to respond to mouse events
on a
paragraph does work.

<HTML>
<SCRIPT Language="JavaS cript">
document.write( "Tex");
function QQ(event){
alert("Displayi ng Mouse Coordiantes "+event.cli entX
+","+event.clie ntY);
}

</SCRIPT>
<body>
<P onmousedown="QQ (event)">Testin g</P>
</body>
</html>
However you can get the mouse(!) coordinates of a MOUSE action.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 14 '07 #2

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

Similar topics

1
3504
by: dave | last post by:
I've designed a nice little App that works something like a spreadsheet using the MSHFlexgrid control. Many users are inclined to press the tab key, expecting the program to respond like excel would but it doesn't. It simply leaves the MSHFlexgrid ang they loose the data they were entering in the particular cell. Is there some way I can receive the tab keypress in some event processing routine so I can respond as I do with a return...
2
8227
by: Ian Henderson | last post by:
I am currently trying to teach myself .NET (specifically vb.NET). I have been working with VBA in Access 97 for a few years now, and consider myself to be quite proficient. At present, I have an issue with the concept of detecting keypresses. I use this frequently in Access 97, generally for giving the user an keyboard-based alternative to clicking on command buttons. For example, if I have a form where the user will be entering...
9
3809
by: robert_rowe | last post by:
Does anyone know how to detect keypresses in a Datagrid cell? The Keypress event ofthe datagrid doesn't fire if you are in a cell. Neither does KeyUp & KeyDown. I've tried hooking in to the DataGridCell events but it doesn't have the keypress event. Robert
1
1483
by: Jean-François Michaud | last post by:
Hello people, I was wondering how it I could implement keep with next logic on lines of text contained within a paragraph. I need to have at least 10 lines of text within a paragraph to be keep together on the first page if we are to split the flow of the paragraph across 2 pages. If it can't be done, the whole paragraph has to cross over.
1
1428
by: abhas59 | last post by:
hi friends, I want to serialize a System.Windows.Documents.Paragraph and for this I have written the following code in the application : mypara cust = new mypara(); Paragraph ph = new Paragraph(new Run(str)); cust.Para = ph; cust.Para.Foreground = System.Windows.Media.Brushes.AliceBlue; string pass = format.Serialize(cust.Para); mypara is a custom class...
15
19874
by: Yogi | last post by:
Hi there, I have a quick question. In my html document, I want to make a new paragraph whenever I have a blank line in the html source. Using <p> and </pevery time is kind of cumbersome (I want to do it the LaTeX way). Is it possible at all? Thanks for your time, Yogi
1
1253
by: Sparky74 | last post by:
Hi. There are so many help offerings out there for the detection of keypresses. I would like to know what the "correct way" is to intercept a keypress for a control. I have overidden the ProcessKeyPreview() method on a PropertGrid and I'm trying to intercept the arrows keys. Whats bugging me is that the wParam value is returning 0x25 (37) for an arrow keypress - this is the same as the ASCII % (percent) symbol. Worse still, I also want to...
3
2318
by: gentsquash | last post by:
I'm trying to display a paragraph that has a centered phrase, such as this one, in the middle of the paragraph. An example is the section "End of semester project" on my course-page http://www.math.ufl.edu/~squash/course.calc3.html
6
2031
by: Haines Brown | last post by:
I'm trying to resolve a contradictory situation in which I have rows going down a page, and each consists of two elements: to the left is a thumbnail image that is a hot link; to its right is a brief descriptive paragraph. The contradiction is that if I float the image to the left, the text in the paragraph is shifted right in its the paragraph box by the amount of the image width; if I put the text where I want it closer to the image...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.