Forcing action on hitting 'return' in textfield

Is there a way to do the following:

When a user enters info into a textfield and hits RETURN/ENTER a script calls.

There will be no form tag, because I do not want it to submit, just call the javascript action.

<input name="info" type="text" id="info" size="40"/ onEnter="JavaScript:alert("TEST");">

Basically I want it to act like it normally would when being submitted in a form tag, just without the form tag, and calling the alert instead.
LVL 1
mopar003Asked:
Who is Participating?
 
ZvonkoSystems architectCommented:
Sorry, it should be other quote chars:

<form onSubmit='JavaScript:alert("TEST");return false;' >
<input name="info" type="text" id="info" size="40" >
</form>

0
 
ZvonkoSystems architectCommented:
You can filter the event codes which are different objects for IE and Netscape or you add a form tag and kill the submit action.
Like this:
<form onSubmit="JavaScript:alert("TEST");return false;">
<input name="info" type="text" id="info" size="40" >
</form>

0
 
mopar003Author Commented:
Perfect.  It was the 'return false' that I was missing.  Thanks for the quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.