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
  • 47,274
  • 54
  • 131
  • 219

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
  • 13,194
  • 4
  • 31
  • 36
2
$('#name, #last').bind('keydown', function(e) {
                    if (e.keyCode == 13 || e.keyCode == 108) {
                        doit();
                    }
                });

KeyCode can be found here

CoffeeCode
  • 4,296
  • 9
  • 40
  • 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,362
  • 3
  • 27
  • 23