472,794 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

javascript:keysuppress(event)

How can I make the following code run only when the cursor is in one
text box and not in another?
<body onkeypress="javascript:keysuppress(event)"
function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}

This would be for I.E. 5.5 and later.

Jul 23 '05 #1
3 1631
Ivo
"Marcia Gulesian" wrote
How can I make the following code run only when the cursor is in one
text box and not in another? This would be for I.E. 5.5 and later.

<body onkeypress="javascript:keysuppress(event)"

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}


Set the handler on the textbox and not on the body element. And remove the
"javascript:" bit. That would be the quickest, I think. Or identify your
textboxes and test for an id in the function before deciding on a return
value.
HTH
Ivo
Jul 23 '05 #2
Ivo,

How exactly do I identify my textboxes and test for an id in the function ?

Thanks,

Marcia

Ivo wrote:
"Marcia Gulesian" wrote
How can I make the following code run only when the cursor is in one
text box and not in another? This would be for I.E. 5.5 and later.

<body onkeypress="javascript:keysuppress(event)"

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}


Set the handler on the textbox and not on the body element. And remove the
"javascript:" bit. That would be the quickest, I think. Or identify your
textboxes and test for an id in the function before deciding on a return
value.
HTH
Ivo


Jul 23 '05 #3
I got it:

document.activeElement.getAttribute("name")

Marcia Gulesian wrote:
Ivo,

How exactly do I identify my textboxes and test for an id in the function ?

Thanks,

Marcia

Ivo wrote:
"Marcia Gulesian" wrote
How can I make the following code run only when the cursor is in one
text box and not in another? This would be for I.E. 5.5 and later.

<body onkeypress="javascript:keysuppress(event)"

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}


Set the handler on the textbox and not on the body element. And remove the
"javascript:" bit. That would be the quickest, I think. Or identify your
textboxes and test for an id in the function before deciding on a return
value.
HTH
Ivo


Jul 23 '05 #4

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

Similar topics

3
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
2
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.