?
Solved

Input text displays keys pressed even though it does not have focus

Posted on 2005-03-22
10
Medium Priority
?
247 Views
Last Modified: 2008-03-10
Hi Experts!
I have a sample HTML page, with two frames. Here is the code for focusTest.html:
<html>
<frameset rows="150,*" > 
      <frame name="frame1" src="goto.html" >
      <frame name="frame2" src="goto.html" >      
</frameset>
</html>

And here is the code for goto.html:
<html>
<body   >
<input size=10 type="text" name="text1" >
<a href="javascript:alert('Hello')">test</a>
</body>
</html>

After the page is loaded, click in the first input box, type couple of characters. Then click the SECOND test link, a Hello is alerted. At this time, the second test link has the input focus. If you hit ENTER now, alert occurs again.
But if you just  type some alphanumeric keys, the FIRST edit box shows those chars, as if it has focus.
This does not happen if the FIRST test link is clicked.

How can I avoid this? I need the text box to accept and display chars only if it has focus. Or atleast, when a char is entered, the text box should get focus.

this is in IE6.0

Thanks in advance for your prompt help!!
0
Comment
Question by:chennarh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 13602273
<a href="#" onclick="alert('Hello');return false;">test</a>

-r-
0
 

Author Comment

by:chennarh
ID: 13602402
Roonaan,
Thanks for your quick response.
That did not work. And also, this is just a sample to demo that IE6.0 blur is screwed up. In my real application, I will be loading various third party html pages or some dynamic content from our servers. I cannot apply this fix all the links in those pages.

We need a workaround from the INPUT box perspective, or at the worst case within the goto.html in frame1.

chennarh
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 13602599
try this

<a href="javascript:alert('Hello');this.focus( );">test</a>


or this

<a href="javascript:alert('Hello');formname.controlname.blur( );">test</a>

or this if it is in a different frame

<a href="javascript:alert('Hello');top.frames[ 'framname' ].form[ 0 ].controlname.blur( );"> Test </a>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:chennarh
ID: 13602704
thanks jsutin, but they donot work. Problem is the input box has already lost focus, i tested with debug statements. Please refer to my earlier comment.
0
 
LVL 3

Expert Comment

by:alexandermancera
ID: 13603460
Hi!

Try this, work fine for me:

<a href="javascript:alert('Hello');window.focus();">test</a>
0
 

Author Comment

by:chennarh
ID: 13603551
This works.  But this involves modifying the html in second frame.  Please see my previous comment.

Thanks!
0
 
LVL 3

Expert Comment

by:alexandermancera
ID: 13603575
Tou can do this too:

<input size=10 type="text" name="text1" onblur="window.focus();">
0
 

Author Comment

by:chennarh
ID: 13604987
If the first frame html, if I add one more text box, then we cannot tab from the first textbox or click in second (have to click twice).
please donot get me wrong, I am not trying to be picky here. Since I am working on a corporate web application, I cannot afford to alter the standard user interaction.

If no one else posts a better solution, I will be happy to accept your answer.
0
 
LVL 3

Accepted Solution

by:
alexandermancera earned 2000 total points
ID: 13605454
>> Problem is the input box has already lost focus.

This isn't right. In IE, When focus leaves the document (or window), the active element does not change (the input not lost focus) and the onbeforedeactivate event will not fire.

You can try this, but only work in IE6+, because event.toElement only exists in IE6+.

If event.toElement is null then the focus leave the document:

<input size=10 type="text" name="text1" ondeactivate="if(!event.toElement)window.focus();">

0
 

Author Comment

by:chennarh
ID: 13606250
Thank you alex!!  this works perfectly for my situation...
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question