home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 June
/
PCWorld_2004-06_cd.bin
/
komunikace
/
slimb
/
sbsetup.exe
/
$_14327_
/
ExtractActiveFormData.js
< prev
next >
Wrap
Text File
|
2003-06-18
|
2KB
|
103 lines
ExtractActiveFormData();
function ExtractActiveFormData()
{
var topBody = top.document.body;
var vForm=GetActiveForm();
topBody.sbFormData=ExtractFormData(vForm);
}
function GetActiveForm()
{
var vForm;
vForm=GetActiveFormEx(true);
if (vForm==null) vForm=GetActiveFormEx(false);
return vForm;
}
function GetActiveFormEx(path,bActive)
{
var vDocument=eval(path+".document");
var vForm;
if (bActive)
{
vForm=vDocument.activeElement.form;
if (vForm!=null)
{
vForm.path=path;
return vForm;
}
}
else
{
vForm=vDocument.forms[0];
if (vForm!=null)
{
vForm.path=path;
return vForm;
}
}
for(var i=0; i<vWindow.frames.length; i++ )
{
vForm=GetActiveFormEx(path+".frames["+i+"]",bActive);
if (vForm!="") return vForm;
}
return null;
}
function ExtractFormData(vForm)
{
var sbFormData;
for(var i=0;i<activeForm.elements.length;i++)
{
var elem=activeForm.elements[i];
var t=elem.type;
if (elem.name==null || elem.name=="") continue;
var en=elem.name;
var tn=elem.tagName.toLowerCase();
s="";
if (tn=="input")
{
if (t=="text")
{
s=en+"="+elem.value;
}
else if (t=="checkbox" || t=="radio")
{
if (elem.checked) s=en+"=1";
else s=en+"=0";
}
else if (t=="password")
{
s=en+"=$sbpswd:"+elem.value;
}
}
else if (tn=="select")
{
s="";
for (var j=0;j<elem.options.length;j++)
{
var opt=elem.options[j];
if (opt.selected)
{
if (s!="") s=s+"|";
s=s+opt.text;
}
}
s=en+"="+s;
}
else if (tn=="textarea")
{
s=elem.value;
s.replace(/\r/g,"\\r");
s.replace(/\n/g,"\\n");
s=en+"="+s;
}
if (s=="") continue;
if (sFormData=="") sFormData=s;
else sFormData=sFormData+"&"+s;
}
return sFormData;
}