471,071 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 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 1590
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 discussion thread is closed

Replies have been disabled for this discussion.

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.