Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Jun 29, 2000

Submitting a Form with the Enter Key

Using the IE browser application, you can press the <Enter> key while filling a form to submit the form. Indeed, this is a desirable feature for any Windows application. In order to make this work for all browser applications, you just need to add a few lines of code.

The method explained here traps the keyboard events to implement this. This works on all browsers —it was tested on Internet Explorer, Netscape Navigator, Mozilla and Opera.

 
<script language="JavaScript">
function processEnterKey(evnt) {
    if (evnt.which == 13)
        document.myForm.submit();
}

if (navigator.appName != "Microsoft Internet Explorer")
    captureEvents(Event.KEYDOWN);
onkeydown = processEnterKey;
</script>
'myForm' identifies the form to be submitted. If the document has several forms, you may need additional logic to determine which form to submit.

Ajith Prasad
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap