• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus issue in IE

 
Deva Devan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Filename: pressing tab for set focus.bmp
Description:
File size: 178 Kbytes
[Download pressing tab for set focus.bmp] Download Attachment
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deva Devan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rufus Addis,

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

Thanks for your help.

Regrads,
Deva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic