home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 July / CMCD0703.ISO / Software / Freeware / Comunicatii / slim / sbrowser.exe / biscripts / ExtractActiveFormData.js < prev    next >
Text File  |  2003-05-29  |  2KB  |  95 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 vWindow=eval(path);
  20.     var vForm;
  21.     if (bActive)
  22.     {
  23.         vForm=vWindow.document.activeElement.form;
  24.         if (vForm!=null) return vForm;
  25.     }
  26.     else 
  27.     {
  28.         vForm=vWindow.document.forms[0];
  29.         if (vForm!=null) return vForm;
  30.     }
  31.     for(var i=0; i<vWindow.frames.length; i++ )
  32.     {
  33.         vForm=GetActiveFormEx(path+".frames["+i+"]",bActive);
  34.         if (vForm!="") return vForm;
  35.     }
  36.     return null;
  37. }
  38.  
  39. function ExtractFormData(vForm)
  40. {
  41.     var sbFormData;
  42.     for(var i=0;i<activeForm.elements.length;i++)
  43.     {
  44.         var elem=activeForm.elements[i];
  45.         var t=elem.type;
  46.         if (elem.name==null || elem.name=="") continue;
  47.         var en=elem.name;
  48.         var tn=elem.tagName.toLowerCase();
  49.         s="";
  50.         if (tn=="input")
  51.         {
  52.             if (t=="text") 
  53.             {
  54.                 s=en+"="+elem.value;
  55.             }
  56.             else if (t=="checkbox" || t=="radio") 
  57.             {
  58.                 if (elem.checked) s=en+"=1";
  59.                 else s=en+"=0";
  60.             }
  61.             else if (t=="password") 
  62.             {
  63.                 s=en+"=$sbpswd:"+elem.value;
  64.             }
  65.         }
  66.         else if (tn=="select")
  67.         {
  68.             s="";
  69.             for (var j=0;j<elem.options.length;j++)
  70.             {
  71.                 var opt=elem.options[j];
  72.                 if (opt.selected) 
  73.                 {
  74.                     if (s!="") s=s+"|";
  75.                     s=s+opt.text;
  76.                 }
  77.             }
  78.             s=en+"="+s;
  79.         }
  80.         else if (tn=="textarea")
  81.         {
  82.             s=elem.value;
  83.             s.replace(/\r/g,"\\r");
  84.             s.replace(/\n/g,"\\n");        
  85.             s=en+"="+s;
  86.         }
  87.         if (s=="") continue;
  88.         if (sFormData=="") sFormData=s;
  89.         else sFormData=sFormData+"&"+s;
  90.     }
  91.     return sFormData;
  92. }
  93.  
  94.  
  95.