faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

104 of 141 people (74%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I let a FORM being submitted with the enter key without using Submit button on the form?

Aug 31st, 2000 07:40
Martin Honnen, sudhir vk,


You can capture key events at the document level and submit the form 
when the enter key is pressed:
  if (document.layers)
    document.captureEvents(Event.KEYPRESS);
  document.onkeypress = function (evt) {
    var key = 
      document.all ? event.keyCode :
      evt.which ? evt.which : evt.keyCode;
    if (key == 13) 
      document.formName.submit();
  };