Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I exit a text box when enter is pressed 1

Status
Not open for further replies.

JerMyster

IS-IT--Management
Mar 17, 2003
49
US
I'm a newbie to HTML and can't for the life of me figure how to create a text box that executes a function when the user presses the ENTER key.

I've looked around the form and can't find it.

Any help, appreciated
 
I guess the question is, what do you regard as a text box. If by text box you mean textarea, enter key will result in a new line. If you want to dabble with that functionality (although I wouldn't), you would need to ask in the javascript forum (forum216). If by text box you mean text input box, then enter key will execute default action in a form -- you can probably work with the onsubmit event handler then.
 
Thanx for your very quick response. I'll try it and also go to the javascript form.

Quick question: what book would you reccomend for javascrip commands/refferences/functions. etc ?
I'm and experienced programmer (VB/VFP) but can't seem to get a handle on the wen orientred structure.

 
You can try the onkeypress event and then fire a subfunction based on the key press value.
For example I threw this together.

Code:
<html>
<head>
<script type="text/javascript">
function lolEvent(event)
{
event.keyCode == 13 ? alert("lol") : alert("notlol");
}

</script>
</head>

<body>
<form>
Press enter to make me lol:
<input type="text" onkeyPress="lolEvent(event)">
</form>

</body>

</html>

I don't know the answer but my good friend Google does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top