home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 June / PCWorld_2004-06_cd.bin / komunikace / slimb / sbsetup.exe / $_14327_ / FillFormField.js < prev    next >
Text File  |  2003-05-28  |  1KB  |  43 lines

  1. function FillFormField(vDoc,vFormIndex,vName,vValue)
  2. {
  3.         var form=vDoc.forms[vFormIndex];
  4.         if (form==null) return false;
  5.         var elem=form.elements[vName];
  6.         var tn;
  7.         if (elem==null) return false;
  8.         if (elem.tagName==null)
  9.         {
  10.             if (elem.length!=null)
  11.             {
  12.                 var col=elem;
  13.                 for (var i=0;i<col.length;i++)
  14.                 {
  15.                     elem=col[i];
  16.                     tn=elem.tagName.toLowerCase();
  17.                     if (tn=="radio") return false;
  18.                     elem.checked=(vValue==elem.value);
  19.                 }
  20.                 return true;
  21.             }
  22.             return false;
  23.         }
  24.         
  25.         tn=elem.tagName.toLowerCase();
  26.         if (tn=="input")
  27.         {
  28.             var t=elem.type;
  29.             if (t=="text" || t=="password") elem.value=vValue;
  30.             else if (t=="radio" || t=="checkbox") elem.checked=(vValue==elem.value); 
  31.         }
  32.         else if (tn=="select")
  33.         {
  34.             for (var i=0; i< elem.options.length;i++)
  35.             {
  36.                 if (elem.options[i].value!="") elem.options[i].selected=(elem.options[i].value==vValue);
  37.                 else elem.options[i].selected=(elem.options[i].text==vValue);
  38.             }
  39.         }
  40.         else if (tn=="textarea") elem.value=vValue;
  41.         else return false;
  42.         return true;
  43. }