home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 February / PCWorld_2005-02_cd.bin / komunikace / slim / sbsetup.exe / ExtractActiveFormData.js < prev    next >
Text File  |  2003-06-18  |  2KB  |  103 lines

  1. ExtractActiveFormData();
  2. function ExtractActiveFormData()
  3. {
  4.     var topBody = top.document.body;
  5.     var vForm=GetActiveForm();
  6.     topBody.sbFormData=ExtractFormData(vForm);
  7. }
  8.  
  9. function GetActiveForm()
  10. {
  11.     var vForm;
  12.     vForm=GetActiveFormEx(true);
  13.     if (vForm==null) vForm=GetActiveFormEx(false);
  14.     return vForm;
  15. }
  16.  
  17. function GetActiveFormEx(path,bActive)
  18. {
  19.     var vDocument=eval(path+".document");
  20.     var vForm;
  21.     if (bActive)
  22.     {
  23.         vForm=vDocument.activeElement.form;
  24.         if (vForm!=null) 
  25.         {
  26.             vForm.path=path;
  27.             return vForm;
  28.         }
  29.     }
  30.     else 
  31.     {
  32.         vForm=vDocument.forms[0];
  33.         if (vForm!=null) 
  34.         {
  35.             vForm.path=path;
  36.             return vForm;
  37.         }
  38.     }
  39.     for(var i=0; i<vWindow.frames.length; i++ )
  40.     {
  41.         vForm=GetActiveFormEx(path+".frames["+i+"]",bActive);
  42.         if (vForm!="") return vForm;
  43.     }
  44.     return null;
  45. }
  46.  
  47. function ExtractFormData(vForm)
  48. {
  49.     var sbFormData;
  50.     for(var i=0;i<activeForm.elements.length;i++)
  51.     {
  52.         var elem=activeForm.elements[i];
  53.         var t=elem.type;
  54.         if (elem.name==null || elem.name=="") continue;
  55.         var en=elem.name;
  56.         var tn=elem.tagName.toLowerCase();
  57.         s="";
  58.         if (tn=="input")
  59.         {
  60.             if (t=="text") 
  61.             {
  62.                 s=en+"="+elem.value;
  63.             }
  64.             else if (t=="checkbox" || t=="radio") 
  65.             {
  66.                 if (elem.checked) s=en+"=1";
  67.                 else s=en+"=0";
  68.             }
  69.             else if (t=="password") 
  70.             {
  71.                 s=en+"=$sbpswd:"+elem.value;
  72.             }
  73.         }
  74.         else if (tn=="select")
  75.         {
  76.             s="";
  77.             for (var j=0;j<elem.options.length;j++)
  78.             {
  79.                 var opt=elem.options[j];
  80.                 if (opt.selected) 
  81.                 {
  82.                     if (s!="") s=s+"|";
  83.                     s=s+opt.text;
  84.                 }
  85.             }
  86.             s=en+"="+s;
  87.         }
  88.         else if (tn=="textarea")
  89.         {
  90.             s=elem.value;
  91.             s.replace(/\r/g,"\\r");
  92.             s.replace(/\n/g,"\\n");        
  93.             s=en+"="+s;
  94.         }
  95.         if (s=="") continue;
  96.         if (sFormData=="") sFormData=s;
  97.         else sFormData=sFormData+"&"+s;
  98.     }
  99.     return sFormData;
  100. }
  101.  
  102.  
  103.