-1

I use this to detect enter:

<input type="submit" name=hiddenbutton value=enter style="display: none">

When this is placed before all other form elements, then I get the appropriate $_REQUEST[hiddenbutton]when enter was used to submit the form.

Except with Chrome and other Webkit-based browsers, which don't activate the first button when enter is pressed.

Is there a way to make it work on all browsers? (preferably with as little JavaScript as possible)

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Robby75
  • 3,285
  • 6
  • 33
  • 52
  • 2
    If you need to detect how exactly the form was submitted you are most likely doing something wrong. What is the problem you are trying to solve with this detection? – Jon Jul 15 '13 at 15:16
  • 1
    Check how to detect event on ENTER key press here: http://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript – achudars Jul 15 '13 at 15:17

1 Answers1

0

I would recomend adding a focus listener to make sure the user is not justdoing something completely different like typing in a word document, because some browsers will detect key clicks without focus

clan
  • 353
  • 2
  • 10