File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes focus() function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "focus() function" Watch "focus() function" New topic
Author

focus() function

R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

focus(), not Focus(). I have corrected the post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vijin das
Ranch Hand

Joined: Jun 07, 2010
Posts: 129

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


VIJINDAS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: focus() function