?
Solved

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

Posted on 2005-03-22
10
Medium Priority
?
262 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
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

601 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