Link to home
Start Free TrialLog in
Avatar of mopar003
mopar003

asked on

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.
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

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>

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia 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
Avatar of mopar003
mopar003

ASKER

Perfect.  It was the 'return false' that I was missing.  Thanks for the quick response.