How to set focus on the last element for which the window pop ups on error
<p>On checking a field against validations, if validation fails , a pop up window is opened.Now when i close the pop up the pop up should return the focus to the last element(in case more than one validation fails for more than one text field). any suggestions ?
My code is:-</p>

<pre><code> function submitformFinal(frm) {
 var message;


 var inputs = frm.getElementsByTagName("input");

     for (var i=0; i &lt; inputs.length; i++)
     {
         if (inputs[i].getAttribute('type') == 'text')
         {

             if(!checkSpecialChars(inputs[i].value))
             {
                  message =  " Special characters found in element = '";
                  message += inputs[i].getAttribute('name') + "'\n";
                  // alert(message);
                  // createPopup(message);

                  MyPopUpWin(message);
             }
        }
    }    
    // return true;
 }

function checkSpecialChars(fileOnlyName)
{
    if ((/[^a-z0-9\.]/gi).test(fileOnlyName)) {

        return false;
    }
    return true;
}

function MyPopUpWin(message) {
    var iMyWidth;
    var iMyHeight;
    //half the screen width minus half the new window width (plus 5 pixel borders).
    iMyWidth = (window.screen.width/2) - (75 + 10);
    //half the screen height minus half the new window height (plus title and status bars).
    iMyHeight = (window.screen.height/2) - (100 + 50);
    //Open the window.
    var generator = window.open();
    document.onclick=function()   {
        try{
            generator.focus();
            return false
        }
        catch(e){}
    }

    generator.document.write('&lt;html&gt;&lt;head&gt;&lt;title&gt;Pop uP&lt;/title&gt;');
    generator.document.write('&lt;p style="color:#C52B27;"&gt;');
    generator.document.write(message);
    generator.document.write('&lt;/p&gt;');
    generator.document.write('&lt;/head&gt;&lt;body&gt;');

    generator.document.write('&lt;a href="javascript:self.close()"&gt;&lt;img src="/img/save_orange.gif" border=0"&gt;  &lt;\/a&gt;');
   generator.document.write('&lt;/body&gt;&lt;/html&gt;');
   generator.document.close();
}
</code></pre>
