lipenco
lipenco

Reputation: 1368

turning off an event on keydown while typing in input element

I am using event which set focus on iframe while pressing enter, space and arrows:

  document.addEventListener("keydown", function (event) {
        if (event.keyCode === 9 || (event.keyCode >= 32 && event.keyCode <= 34) || (event.keyCode >= 37 && event.keyCode <= 40)) {
            setFocusOnIframe();
        }
    }, false);

the problem is that i have input for name, and I would like turn off event listener for space while typing name.

<input id="presentation-name" type="text" placeholder="Add Name">

how should i write the function so as it will not focus on iframe while typing the name on input element?

Upvotes: 0

Views: 102

Answers (1)

Andrew
Andrew

Reputation: 5340

Try this:

var target = event.target || event.srcElement;

if(target.id == "presentation-name")return;

Upvotes: 1

Related Questions