[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

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.
0
mopar003
Asked:
mopar003
  • 2
1 Solution
 
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
 
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
 
mopar003Author Commented:
Perfect.  It was the 'return false' that I was missing.  Thanks for the quick response.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now