473,387 Members | 1,624 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,387 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 1649
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...

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.