Link to home
Start Free TrialLog in
Avatar of fippif
fippif

asked on

How to call javascript when users press Enter

I am using an input type "image" for which "onclick=quotego()" (quotego() is my script). It works fine when users click on the image. But I want to be able to call  my script when users press Enter.

Thanks.

<form>
							<td><table width="180" border="0" cellpadding="0" cellspacing="0" bgcolor="#898989">
							<tr><td width="138" height=38 align=left valign=top class="F_TD_L12"><input type=text class="form3" id=QuoteTicker onclick=clearText("QuoteTicker") value="<Enter ticker for quote>"></td>
							<td width=42 align=left valign=top class="F_TD_L0"><input type=image src=/images/ico_go.gif onclick=quotego()></td>
							</tr>
							</form>

Open in new window

Avatar of Joe Wu
Joe Wu
Flag of Australia image

Have a look at this sample code:
<html>
	<head>
		<title>Script Demo Gops</title>
		<script type="text/javascript">
			function captureEvt(evt){
				evt = (evt) ? evt : event;
				var charCode = (evt.which) ? evt.which : evt.keyCode;
				if(charCode==13) alert("Enter key pressed");
			}
		</script>
	</head>
<body>
	<form name="calcs">
		Press Enter<input type="text" value="" name="emp" onkeypress="captureEvt(event)"><br>
		Press Enter<input type="text" value="" name="val" onkeypress="captureEvt(event)"><br>
	</form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gops1
gops1
Flag of United States of America 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