javascript - How to set focus on the last element for which the window pop ups on error -


on checking field against validations, if validation fails , pop window opened.now when close pop pop should return focus last element(in case more 1 validation fails more 1 text field). suggestions ? code is:-

 function submitformfinal(frm) {  var message;    var inputs = frm.getelementsbytagname("input");       (var i=0; < 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 screen width minus half new window width (plus 5 pixel borders).     imywidth = (window.screen.width/2) - (75 + 10);     //half screen height minus half new window height (plus title , status bars).     imyheight = (window.screen.height/2) - (100 + 50);     //open window.     var generator = window.open();     document.onclick=function()   {         try{             generator.focus();             return false         }         catch(e){}     }      generator.document.write('<html><head><title>pop up</title>');     generator.document.write('<p style="color:#c52b27;">');     generator.document.write(message);     generator.document.write('</p>');     generator.document.write('</head><body>');      generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0">  <\/a>');    generator.document.write('</body></html>');    generator.document.close(); } 

in code, use:

mypopupwin(message); <- existing line inputs[i].focus() 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -