?
Solved

onBlur, self.focus: form headache

Posted on 2004-04-15
1
Medium Priority
?
847 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
[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
1 Comment
 
LVL 12

Accepted Solution

by:
lil_puffball earned 375 total points
ID: 10837970
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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

765 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