aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Focus issue in IE 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 issue in IE" Watch "Focus issue in IE" New topic
Author

Focus issue in IE

Deva Devan
Ranch Hand

Joined: Sep 22, 2010
Posts: 39
Hi,

Please find the following sample program. I am setting focus to the button in onLoad() method. It setting but not highlighted.

Once click this button the focus will move to select box ( check box). That focus moved to checkbox but not visible or highlighted.

Please suggest me the solution.


Sample Code :

<html>
<head>
<script type="text/javascript">
function loadData(){
document.getElementById('but').focus();

}
function msg(){
document.getElementById('select').focus();
}
</script>
</head>
<body onLoad="loadData()">
<input type="button" name="but" value="Click me" onclick="msg()" /></br>
<input type="checkbox" name="select">SelectMe</input>
</body>
</html>

Note: The Focus is setting on that component, but i cant find where is the focus is setting. If you press tab, you can understand my issue.

Thanks.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
jhon masco
Ranch Hand

Joined: May 13, 2010
Posts: 93

Hi Deva
You have a "small" mistake in you html code.
In javascript code you wrote:

is to say, you are calling the element by the ID name but.... in you html code you forget to put the ID name!

the correct way is:

and it will work.
Deva Devan
Ranch Hand

Joined: Sep 22, 2010
Posts: 39
Hi John,

Thanks for your reply.

But, here i am using name as id. That is not a problem.
That code also working which way i am using.
what is my problem is the focus is setting on the component, but it not visible.
If we press tab for setting the focus, the focus will be set in the component with doter [-----]box on the component[please check the attachment].
But the doter line is missing when i am setting focus in my code.
I hope you got my problem.

Please check the attached screen shot which i want.

Thanks in advance,

Deva


[Download pressing tab for set focus.bmp] Download

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Deva devan wrote:But, here i am using name as id. That is not a problem.

Yes, it is. name and id are not interchangeable. Some toy browsers that don't follow standards may allow it, but others may not. Do it the right way and make sure that you use id for all elements that need to be referenced.

Also, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deva Devan
Ranch Hand

Joined: Sep 22, 2010
Posts: 39
Hi Bear Bibeault,

Thanks for your guidance.

I changed my code with ID.



but it not returns expecting result. Please check my previous post and attachment.

Thanks,

Deva
Rufus Addis
Ranch Hand

Joined: Aug 21, 2008
Posts: 83
Hi Deva,

I think a major part of the problem is that the browser is using Quirks mode which at best has unpredictable results. It's worth getting in to the habit of making sure any HTML you write has a doctype specified. At its simplest replace the <html> with:



Testing your latest sample html (with id's specified) and adding a doctype, it works for me in IE8, Chrome.

If you are still having problems can reply with details of which browser you are testing in.

Thanks - Rufus.
Deva Devan
Ranch Hand

Joined: Sep 22, 2010
Posts: 39
Hi Rufus Addis,

Its working fine in IE8. (I am using IE7)

Thanks for your help.

Regrads,
Deva
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Focus issue in IE