View Full Version : Making the Enter key to do an Image's onclick() event.

05-12-2009, 10:44 PM
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?

05-13-2009, 03:31 AM
This should get you started....

BTW, wrong forum

05-13-2009, 12:35 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">

function tester()

<form onsubmit="document.getElementById('pic').onclick();return false;">
<input type="text" />
<img id="pic" src="http://www.codingforums.com/img/logo.gif" onclick="tester()" />

Possible solution. The 'return false' stops the form from submitting. Easy to alter, depending what you want to do.