PsychoSpunk has asked for the wisdom of the Perl Monks concerning the following question:

Before you get all abrasive, this is not truly OT, but close enough to warrant the disclaimer. I am using perl to write the javascript based on certain conditions. What I want to know is can I write something like the following pseudocode: document.form.description_box.focus() unless window.new.hasFocus;

I've got a form that grabs focus in a text input field. When you submit the form it saves the info in the database and it returns to the same page that you come from. New complications have come up so that I have to pop-up a window to do extra tasks in specific cases. So I want to keep from giving the focus back to the text input field when it reloads the form in the main window. I have added: onload="self.focus();" into the new window, but that only avoids the problem temporarily by creating a race condition that is favorable to the new window getting focus. But what happens if the other script takes longer to reload the main window and grabs focus after the new one? That's why I want to add code to the main window in the event that a new window exists.

Oh yeah, the form must be submitted in order to have proper values available to the new window. Otherwise, I'd just hold off on executing the form until I had done what I needed in the new window.

ALL HAIL BRAK!!!

Replies are listed 'Best First'.
Re (tilly) 1: OT:A javascript problem.
by tilly (Archbishop) on Oct 04, 2000 at 20:17 UTC
    Either you will need to have some good mutex construction, or else you will need to play games with setting a timeout. Should you set timeouts note that you have to pass it a string to eval as a function, not actual functions. (Gosh darn.)

    If you come up with a good mutex construction to synchronize events, please tell me. I have one that seems to work, but kills the CPU and has a race in it. (Which is, however, very unlikely to be tripped.) I would like a better one.

    Good luck in your JavaScript exile. But two random notes. First of all JavaScript supports anonymous functions, closures, and all that, so that transfers to and from Perl. The second is the fact that JavaScript objects are basically references to hashes. That little translation may allow you to figure out how to apply a few Perlish tricks to your benefit.

RE: OT:A javascript problem.
by Anonymous Monk on Oct 05, 2000 at 11:07 UTC
    Create a variable (hasFocus) in the "old" window (the opener) and let the onload="self.focus();" in the new window be onload="self.opener.hasFocus=1;self.focus();"
    and check for hasFocus.

    /brother t0mas
      It was I who posted this note... I _really_ dislike Internet Explorer. Sometimes it logs me out from PM by itself. Has anyone else had this problem with IE?

      /brother t0mas