Highlights:

Tags:

Archives:

Subscription:

To subscribe/unsubscribe for notifications of new posts to this blog, please login.

The biggest obstacle to success is the statement, "I can't", for once it is uttered and accepted, all chance of success is erased.
Thursday, October 01, 2009

As I develop applications for the browser, I'm constantly plagued by the little "gotchas" that lie waiting for me.  Generally, it can be attributed to differences in how Internet Explorer (IE) and Firefox handle things.  In this case, I simply wanted a little routine that entered text into a textbox and then sent the cursor there.  Firefox, my default browser, did this as expected.  IE, however, chose to place the cursor at the beginning of the text so that the user still had to move to the end of the input to start typing.

Here's my solution...

It's actually quite simple:

        if (myTextbox.createTextRange) {
            var trange = myTextbox.createTextRange();
            trange.moveStart('character', (myTextbox.value.length));
            trange.collapse();
            trange.select();
        }

That's all there was to it.  Enjoy!