Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

focus() function

 
R Naijat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I have a text input field, when the user typing in the field, onKeyUp() function is called and I do some processing on the content in the field. In order to set the focus and cursor back to the filed, I use the focus() function as follows:



My OS is Windows 7. focus() works correctly in Chrome 15.0, meaning if the contents of the field is already ABC, the cursor appears right after C, so if the user enters D, the contents of the field would be: ABCD.

In FireFox 8.0, the cursor appears at the beginning of the field, meaning if the contents of the field is already ABC, the cursor appears before A, so if the user enters D, the contents of the field would be: DABC.

And in IE 8.0, the focus() does not work at all! The field looses the focus completely and I need to use the mouse to set the focus back to the field.

Two questions:

1) Does anybody know why this function does not work properly in IE?

2) For FireFox: is there anyway, I can make the focus appears at the end of the field instead? Or on the other words is there anyway I can make the functionality the same in FireFox as it does in Chrome?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
focus(), not Focus(). I have corrected the post.
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naijat

My suggestion is use jquery so that you can omit some of the browser related issues ...

you can use .focus() function in jquery . check Jquery Focus Doc

This is just a suggestion ...

Regards

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic