Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery focus out after pressing enter key

My code is below:

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).focusout();

    }
});

As you can see on the code above, When a user presses the enter key first callajax() is run(working fine). After that I want to focus out from the .summaryT input box, How can I achieve this?

like image 638
Friend Avatar asked Sep 12 '13 07:09

Friend


3 Answers

Try this

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).blur();    
    }
});
like image 148
Bibhu Avatar answered Oct 15 '22 17:10

Bibhu


Since AJAX stands for asynchronous, you may want to call focusout() after the call successfully finished.

like image 34
fabrik Avatar answered Oct 15 '22 17:10

fabrik


use the jquery blur() event

$('.summaryT').keypress(function(e){
    if(e.which == 13){
        callajax();
        $(this).blur();

    }
});
like image 21
Liam Allan Avatar answered Oct 15 '22 15:10

Liam Allan