views:

54

answers:

3

Hi, 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

+2  A: 
$('#name, #last').bind('keydown', function(e) {
                    if (e.keyCode == 13 || e.keyCode == 108) {
                        doit();
                    }
                });

KeyCode can be found here

CoffeeCode
I mean the RETURN button in keyboard
David
what do u mean bu the return button?? backspace?
CoffeeCode
RETURN should either be ENTER (13) or NUMPAD_ENTER (108)
Ian Clelland
A: 

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

derivation
+3  A: 

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
Hmm... looks nice :)
CoffeeCode
Thanks a bunch!
David