Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript: Identifying a Link when Enter Key pressed 1

Status
Not open for further replies.

DLLHell

Programmer
May 9, 2003
69
0
0
US
I have a HTML link - I am using an onkeypress to check for an Enter key (value 13). Problem is the event is valid if certain links are clicked or if one of the links had focus (tabbed to) when the Enter key was pressed.

Is there a way to know in JS that the focus was on one of the links (and which one) when the Enter key was pressed? Any examples here would be helpful enough to steer me on the right path.

My apologies if this turns out to be a stupid question. Thanks.
 
You can get a handle to the element that triggered the event using the
Code:
event.srcElement
property.

Code:
function keypresshandler(){
 var sourceElement = event.srcElement;
 alert(sourceElement.tagName);
 alert(sourceElement.id);
}

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

AU.gif
Check out Tek-Tips Australia New Zealand forum1155
NZ.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top