473,403 Members | 2,071 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,403 software developers and data experts.

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="JavaScript">
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="JavaScript">
document.write("Tex");
function QQ(event){
alert("Displaying Mouse Coordiantes "+event.clientX
+","+event.clientY);
}

</SCRIPT>
<body>
<P onmousedown="QQ(event)">Testing</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 1695
wrote on 14 apr 2007 in comp.lang.javascript:
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="JavaScript">
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="JavaScript">
document.write("Tex");
function QQ(event){
alert("Displaying Mouse Coordiantes "+event.clientX
+","+event.clientY);
}

</SCRIPT>
<body>
<P onmousedown="QQ(event)">Testing</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
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...
2
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...
9
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...
1
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...
1
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...
15
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...
1
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...
3
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 ...
6
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...
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: 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...
0
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...
0
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...

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.