...

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



sdsdsd
05-12-2009, 11: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?

twodayslate
05-13-2009, 04:31 AM
This should get you started....
http://jennifermadden.com/javascript/stringEnterKeyDetector.html

BTW, wrong forum

adios
05-13-2009, 01:35 PM
<!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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum