?
Solved

How to call javascript when users press Enter

Posted on 2007-11-16
3
Medium Priority
?
6,590 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:fippif
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20302932
0
 
LVL 17

Expert Comment

by:gops1
ID: 20302969
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

0
 
LVL 17

Accepted Solution

by:
gops1 earned 500 total points
ID: 20303947
Input type image is like submit button. In this case do it this way:

<html>
	<head>
		<title>Script Demo Gops</title>
		<script type="text/javascript">
			function quotego(){
				alert("Here");
			}
		</script>
	</head>
<body>
<form onsubmit="return quotego()">
	<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"></td>
		</tr>
	</table>
</form>
</body>
</html>

Open in new window

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question