473,287 Members | 3,240 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,287 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 1648
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...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.