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.
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>
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/22059102/How-to-capture-tab-or-enter-key-stroke.html