0

i have two text inputs like the following, i don't want to use <form> , so i want when people press "return" BUTTON after filling the inputs, a function called "doit()" should be executed.

<script>
function doit(){
alert("you submitted the info");
..........ajax code........
}
</script>

<input type="text" id="email" />
<input type="text" id="skills" />

Thanks

CodeOverload
  • 45,400
  • 52
  • 128
  • 215

3 Answers3

3

The following will do what you are looking for.

$('#emails, #skills').keypress(function(e){
   if( e.keyCode == $.keyCode.ENTER || e.keyCode == $.keyCode.NUMPAD_ENTER ){
     yourSubroutine();
   }
});
Danny
  • 11,944
  • 4
  • 28
  • 36
2
$('#name, #last').bind('keydown', function(e) {
                    if (e.keyCode == 13 || e.keyCode == 108) {
                        doit();
                    }
                });

KeyCode can be found here

CoffeeCode
  • 4,266
  • 8
  • 38
  • 55
0

Check out this question. Essentially, you'll want to bind a keypress listener, and then check for the return key.

Community
  • 1
  • 1
derivation
  • 4,022
  • 3
  • 25
  • 23