Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Making the Enter key to do an Image's onclick() event.

    I have a text box and an image which when clicked performs some function. How can I capture the Enter key in the text box and make it to perform the image's onclick event. It needs to be functional across diff browsers. Is there a Javascript code for it?

  • #2
    Senior Coder twodayslate's Avatar
    Join Date
    Mar 2007
    Location
    VA
    Posts
    1,042
    Thanks
    67
    Thanked 39 Times in 39 Posts
    This should get you started....
    http://jennifermadden.com/javascript...yDetector.html

    BTW, wrong forum
    twitter | Quality Hosting - $5.95/mo*
    Feel free to PM me!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>untitled</title>
    <script type="text/javascript">
    
    function tester()
    {
       alert('clicked');
    }
    
    </script>
    </head>
    <body>
    <form onsubmit="document.getElementById('pic').onclick();return false;">
    <input type="text" />
    </form>
    <img id="pic" src="http://www.codingforums.com/img/logo.gif" onclick="tester()" />
    </body>
    </html>
    Possible solution. The 'return false' stops the form from submitting. Easy to alter, depending what you want to do.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •