Link to home
Start Free TrialLog in
Avatar of bganoush
bganoush

asked on

Simulate click in link with a key stroke...

Hello World!

I have a page that contains a dynamic anchor link and image and I would like the user to be able to press enter to automatically follow that link.  I was able to do this but I'm not sure if this is the right solution. I guess my question is ... Is this the only or best way to simulate a click with a key stroke?

Here is what I have so far:

<HTML>
<HEAD>

<SCRIPT TYPE="text/javascript">
      function DoKeyPress()
      {
            if (event.keyCode== 13)
            {
                  //Submit Anchor link...
                  var elem = document.getElementById('mylink');
                  window.location = elem;                  
            }
      }
</SCRIPT>
</HEAD>
<BODY onload="document.onkeypress=DoKeyPress;">
      <H1>This is a test</H1>
      <A id=mylink href="http://www.yahoo.com"><IMG src="mylinkimage.gif"></A><BR>
</BODY>
</HTML>



-- Bubba
ASKER CERTIFIED SOLUTION
Avatar of system_down
system_down
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bganoush
bganoush

ASKER


Thanks,

We don't support Firefox here but it's good to have a complete solution.

-- Bubba

Your welcome.
S_D