views:

35

answers:

1

I have an realy nasty problem with focus in internet explorer.

I have a textarea for inputing text. This textarea is not visible for the user and is only used to provide robust text input for a more advanced view.

As the textarea isn't visible and shouldn't be i use textarea.focus() in the javascript to activate text-input. This has worked fine until now where i get really wierd results.

For the textinput i basically use this event plus an exact copy for onkeypress.

textarea.onkeyup = function (e) {
        //textarea.value contains the full text
        //Update the view with this value
};

The problem is that sometimes textarea.value is not updated. I can even see the button in e.keyCode on the keyup event above but the value isn't changed. This seems to happen after i have clicked somewhere on the page, but this does not trigger a blur-event. I'm logging the onfocus- and onblur-events so i can see when the textarea looses focus but it doesnt. And i still receive the keyup/press/down events.

If i try to refocus the textarea with textarea.focus() the problem remains. A workaround i found though is to focus the window with window.focus() and right after call textarea.focus(). The problem with this is that focus is a really expensive operation in IE (no kidding) and since i cannot detect when this problem will happen i have to keep doing it with certain interval which seriously affects the performance of my application (involves animation etc).

I use the exact same code for other browsers and do not have this problem there.

A: 

Change the identifier to something less generic like "textAreaAdv", IE sometimes get confused with this word.

Brandon
In my code it's actually called something different already but thanks for the advice.
elm