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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap spacebar key on a link? 1

Status
Not open for further replies.

ketankshah

IS-IT--Management
Jan 11, 2001
121
IN
I want to trap the spacebar key on a link. i.e. If the focus is on a link and the user presses spacebar, then I want to call a function otherwise not.

<a href=&quot;#&quot; onkeydown=&quot;check()&quot;><img src=&quot;check.gif&quot;></a>

This code will call the check function irrespective of any key is being pressed. I want to call it only when the user presses spacebar.

How can I do it?

Ketan
 
For IE:


<a href=&quot;#&quot; onkeypress=&quot;javascript:if(window.event.keyCode==32){check(this)}&quot;>Click here</a>
<script language=javascript>
function check(theField)
{
alert(&quot;Function called&quot;)

}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top