VBScript Sample: vbscript/ado/animals/animals.asp
   ASP Script
   Comments or Client-side Script
   HTML and Text

<%@ Language=VBScript %>
<%
   dbms = Request.QueryString("dbms")
   movecnt = Request.QueryString("movecnt")
   dim path, pos
   dim fs, f, fc

   path = Server.mappath("register.asp")
   path = Replace(path, "\", "/")
   pos = InStr(1,path,"animals")
   path = Left(path, pos - 1) & "gif/"

   Set fs = Server.CreateObject("Scripting.FileSystemObject")
   Set f = fs.GetFolder(path)
   Set fc = f.Files

   idval = ""
   nameval = ""
   areaval = ""
   hval = ""
   wval = ""
   gifval = "boa.gif"

   set RS = Session("animalsRd")
   if Request.Form("GifField").Count > 0 then
      idval = Request.Form("IdField")
      nameval = Request.Form("NameField")
      areaval = Request.Form("AreaField")
      hval = Request.Form("HeightField")
      wval = Request.Form("WeightField")
      gifval = Request.Form("GifField")

      gifFile = path & gifval
      if Cint( Request.QueryString("chggif") ) = 0 then
         RS.AddNew
         RS("Id") = idval
         RS("Name") = nameval
         RS("Area") = areaval
         RS("Height") = hval
         RS("Weight") = wval
         RS("Gif") = "$file:" & gifFile
         RS.Update
         RS.MoveLast
         movecnt = RS.RecordCount
         Response.redirect "main.asp?dbms=" & dbms & "&movecnt=" & movecnt
      end if
   else
      gifFile = fc.item("boa.gif")
   end if
%>

<HTML>
<HEAD>
</HEAD>
<BODY onLoad="document.form1.GifField.focus();">

<form name=form1 method=post action="main.asp?dbms=<%=dbms%>&movecnt=<%=movecnt%>">
<TABLE width=100%><TR>
<TD align=center width=360>
<table width=100%>
<tr><td align=center width=40%><b>Id:</b></td>
<td width=60%><INPUT name=IdField size=25 value="<%=idval%>"></td></tr>
<tr><td align=center width=40%><b>Name:</b></td>
<td><INPUT name=NameField size=25 value="<%=nameval%>"></td></tr>
<tr><td align=center width=40%><b>Area:</b></td>
<td><INPUT name=AreaField size=25 value="<%=areaval%>"></td></tr>
<tr><td align=center width=40%><b>Height:</b></td>
<td><INPUT name=HeightField size=25 value="<%=hval%>"></td></tr>
<tr><td align=center width=40%><b>Weight:</b></td>
<td><INPUT name=WeightField size=25 value="<%=wval%>"></td></tr>
<tr><td align=center width=40%><b>Gif:</b></td>
<td><select name=GifField width=180 style="WIDTH:180" onchange=ChgPicture()>
<%
   for each ff in fc
      if gifval = ff.name then
%>

<option selected><%=ff.name%>
<%
      else
%>

<option><%=ff.name%>
<%
      end if
   next
%>

</select></td></tr>
<tr><td align=center width=40%><BR>
<INPUT name=register type=button value=" OK " onClick="return regOnClick();"></td>
<td><BR><INPUT type=submit name=back value="Cancel"></td></tr>
</table>
</TD><TD valign=top><img src="<%=gifFile%>" border=0></TD>
</TR></TABLE>
</form>

<hr size="1" color="#000000">
<EM>This is <%=dbms%> database.</EM>
<font size="+1">
<center><a href="selectdb.asp" target=main>
Return Home</a></center></font>
</BODY>

<SCRIPT language=JavaScript>
function ChgPicture(){
   document.form1.action="register.asp?dbms=<%=dbms%>&movecnt=<%=movecnt%>&chggif=1";
   document.form1.submit();
}

function regOnClick(){
   var name = document.form1.IdField.value;
   if (name.length < 1){
      alert("The \"Id\" must be a number.");
      document.form1.IdField.focus();
      return;
   }
   for (i = 0; i < name.length; i++) {
      ch = name.charAt(i);
      if ( ch < '0' || ch > '9' ){
         alert("The \"Id\" must be a number.");
         document.form1.IdField.focus();
         return;
      }
   }

   if (document.form1.NameField.value == "") {
      alert("The \"Name\" can't be empty.");
      document.form1.NameField.focus();
      return;
   }
   if (document.form1.AreaField.value == "") {
      alert("The \"Area\" can't be empty.");
      document.form1.AreaField.focus();
      return;
   }
   name = document.form1.HeightField.value;
   if (name.length < 1){
      alert("The \"Height\" must be a number.");
      document.form1.HeightField.focus();
      return;
   }
   for (i = 0; i < name.length; i++) {
      ch = name.charAt(i);
      if ( ch < '0' || ch > '9' ){
         alert("The \"Height\" must be a number.");
         document.form1.HeightField.focus();
         return;
      }
   }

   name = document.form1.WeightField.value;
   if (name.length < 1){
      alert("The \"Weight\" must be a number.");
      document.form1.WeightField.focus();
      return;
   }
   for (i = 0; i < name.length; i++) {
      ch = name.charAt(i);
      if ( ch < '0' || ch > '9' ){
         alert("The \"Weight\" must be a number.");
         document.form1.WeightField.focus();
         return;
      }
   }

   document.form1.action="register.asp?dbms=<%=dbms%>&movecnt=<%=movecnt%>&chggif=0";
   document.form1.submit();

}
</SCRIPT>

</HTML>


Copyright © 1998-2002, Halcyon Software Inc. All rights reserved.