469,923 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Handling Enter key in text input field?

Is there a way to catch the Enter key being pressed in a text field?
I want to submit the form if Enter is pressed in a particular field.
I have more than one form on the page, each with a submit button but
more than one text field each.

TIA,

-----------------------------------------------------------------
John English | mailto:je@brighton.ac.uk
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------

Jul 20 '05 #1
1 73765
"John English" <je@brighton.ac.uk> wrote:
Is there a way to catch the Enter key being pressed in a text field?
I want to submit the form if Enter is pressed in a particular field.
I have more than one form on the page, each with a submit button but
more than one text field each.


<form ...>
<label ...>Press enter in this field to submit form...</label>
<input type="text" ... onkeypress="handleKeyPress(event,this.form)">
</form>

<script type="text/javascript">
function handleKeyPress(e,form){
var key=e.keyCode || e.which;
if (key==13){
form.submit();
}
}
</script>

HTH,

Vjekoslav
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rosebud | last post: by
13 posts views Thread by Eddie | last post: by
2 posts views Thread by Dave Vinell | last post: by
1 post views Thread by NullBock | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.