Solved

onBlur, self.focus: form headache

Posted on 2004-04-15
1
828 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert on input text 2 25
Send form to asp server side 6 28
Increase counter and attr inside a while loop 15 37
Change javascript filter code from OR logic to AND 5 17
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

730 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