Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Javascript event type

There is a function OPEN in my javascript which is called when the user either blur (lose focus on the input field) or hit Enter.

Then within OPEN(), depending on whether it was triggered by blur or keypress, it leads to two different other functions.

For the Keypress, I did it like this.

        if (e.keyCode==13) ENTER_FX();

How do you do this for BLUR

Thank you

UPDATE:

I found that it should be e.type=="focusout"

So is focusout the right word instead of blur?

like image 878
William Sham Avatar asked Jun 18 '26 01:06

William Sham


1 Answers

WORKING JSFIDDLE EXAMPLE

e.type

gives you this information

function OPEN(e) {
    if (e.type !== "blur") {
        if (e.keyCode === 13) {
            ENTER_FX();
        }
    }
    else {
        ENTER_FX();
    }
}
like image 87
jondavidjohn Avatar answered Jun 19 '26 14:06

jondavidjohn