3

a very simple FORM and JS:

$('#gg').submit(function() {
    alert('s');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="gg" method="post">
    <input name="languageId" type="text">
    <input name="languageName" type="text">
</form>

.submit wont be triggered by pressing enter on an input somehow. But if I have one input, it does work!

John Smith
  • 6,129
  • 12
  • 68
  • 123

3 Answers3

5

Pressing the ENTER key will submit the form if you add a submit input to your form.

    $('#gg').submit(function() {
        alert('s');
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="gg" method="post">
    <input name="languageId" type="text"/>
    <input name="languageName" type="text"/>
    <input type="submit"/>
</form>
Guillaume Georges
  • 3,878
  • 3
  • 14
  • 32
3

One way to accomplish this is to manually setup the enter key press like this:

$('#gg input').keypress(function (e) { // listen to keypress on your input controls
    if (e.which == 13) {   // if enter key...
        $('#gg').submit(); // submit the form
    }
});

Here it is in action: https://jsfiddle.net/8md75a6f/3/

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
0

Actually, adding a

<input type="submit" style="display: none;">

seems to solve everything

John Smith
  • 6,129
  • 12
  • 68
  • 123