Solved

onBlur, self.focus: form headache

Posted on 2004-04-15
1
808 Views
Last Modified: 2008-02-01
Hi.
I have a ** body onblur="self.focus();"  ** tag to keep my page on top, and it works fine, except for that my form fields wont work!

It should have been obious for me: when you focus a form field, your page loses focus, and tries to regain it, so you can't write in the field (darn!).

Can anyone help me on this one?
0
Comment
Question by:tomwoods
1 Comment
 
LVL 12

Accepted Solution

by:
lil_puffball earned 125 total points
Comment Utility
Here's a workaround. Unfortunately, it doesn't work if the user clicks on the form, then on another page. I think this is the closest you'll get though.

Add this to the top of your page:

<script>
function init(){
  for(i=0;i<document.forms.length;i++){
    for(j=0;j<document.forms[i].elements.length;j++){
      document.forms[i].elements[j].onmousedown=function(){document.body.onblur=null;this.focus();}
      document.forms[i].elements[j].onfocus=function(){document.body.onblur=null;this.focus();}
      document.forms[i].elements[j].onblur=function(){document.body.onblur=function(){self.focus();}}
    }
  }
}
</script>

<body onblur="self.focus();" onload="init();">
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now