JScript Sample: jscript/ado/authors/authors.asp
   ASP Script
   Comments or Client-side Script
   HTML and Text

<%@ Language=JScript%>
<HTML>
<HEAD>
<SCRIPT Language = "JavaScript">

function MoveClick(option){
   document.form1.action = "authors.asp?dbms=<%=dbms%>&mode=1&direction=" + option;
   document.form1.submit();
}

function ModeClick(option) {
   if ( option == 1 )
      document.form1.action = "authors.asp?dbms=<%=dbms%>&mode=1&direction=0";
   else
      document.form1.action = "authors.asp?dbms=<%=dbms%>&mode=2&operate=0";
      document.form1.submit();
}

function OperateClick(option) {
   if (option == 3 || option == 5){
      if ( isNaN( parseInt(document.form1.S0.value) ) ){
         alert("Please enter a number for the 'Au_ID' field.");
         return;
      }

      if ( document.form1.S2.value != "" && isNaN( parseInt(document.form1.S2.value) ) ){
         alert("Please enter a number for the 'Year Born' field.");
         return;
      }
   }
   document.form1.action = "authors.asp?dbms=<%=dbms%>&mode=2&operate=" + option;
   document.form1.submit();
}
</SCRIPT>


</HEAD>
<BODY>
<%
   bErr = false;
   mvNext = false;
   mvPrev = false;

   if (Request.Form("drvtxt").Count > 0) {
      drv = parseInt( Request.Form("drvtxt") );
      url = Request.Form("urltxt");
      uid = Request.Form("uidtxt");
      pwd = Request.Form("pwdtxt");

      DrvArry = new Array(15);
      DrvArry[0] = "--Please select a driver--";
      DrvArry[1] = "sun.jdbc.odbc.JdbcOdbcDriver";
      DrvArry[2] = "sun.jdbc.odbc.JdbcOdbcDriver";
      DrvArry[3] = "oracle.jdbc.driver.OracleDriver";
      DrvArry[4] = "com.informix.jdbc.IfxDriver";
      DrvArry[5] = "twz1.jdbc.mysql.jdbcMysqlDriver";
      DrvArry[6] = "org.gjt.mm.mysql.Driver";
      DrvArry[7] = "com.sybase.jdbc2.jdbc.SybDriver";
      DrvArry[8] = "COM.cloudscape.core.JDBCDriver";
      DrvArry[9] = "postgresql.Driver";
      DrvArry[10] = "intersolv.jdbc.sequelink.SequeLinkDriver";
      DrvArry[11] = "intersolv.jdbc.sequelink.SequeLinkDriver";
      DrvArry[12] = "intersolv.jdbc.sequelink.SequeLinkDriver";
      DrvArry[13] = "intersolv.jdbc.sequelink.SequeLinkDriver";
      DrvArry[14] = "intersolv.jdbc.sequelink.SequeLinkDriver";
      DrvArry[15] = "openlink.jdbc2.Driver";

      switch ( drv ) {
         case 1:
         case 14:
            dbms = "Access";
            break;
         case 2:
         case 13:
         case 15:
            dbms = "SQLServer";
            break;
         case 3:
         case 10:
            dbms = "Oracle";
            break;
         case 4:
         case 11:
            dbms = "Informix";
            break;
         case 5:
         case 6:
            dbms = "MySQL";
            break;
         case 7:
         case 12:
            dbms = "Sybase";
            break;
         case 8:
            dbms = "Cloudscape";
            break;
         case 9:
            dbms = "Postgres";
            break;
         default:
            dbms = "";
      }

      strCnn = "Driver=" + DrvArry[drv] + ";URL=" + url + ";UID=" + uid + ";PWD=" + pwd + ";"

      conn = Server.CreateObject("ADODB.CONNECTION");
      conn.Open( strCnn );

      Session("authorsRd") = Server.CreateObject("ADODB.RECORDSET");
      Session("authorsRd").CursorLocation = 3
      Session("authorsRd").Open( "Authors", conn, 2, 2 );
   } else {
      dbms = Request.QueryString("dbms");
   }

   RS = Session("authorsRd");

   mode = parseInt( Request.QueryString("mode") );
   if (mode == 1) {
      direction = parseInt( Request.QueryString("direction") );

      switch ( direction ) {
         case 1:
            if ( !RS.Eof || !RS.Bof )
               RS.MoveFirst();
            }
            break;
         case 2:
            if ( !RS.BOF ) {
               RS.MovePrevious();
               mvPrev = true;
            }
            break;
         case 3:
            if ( !RS.EOF ) {
               RS.MoveNext();
               mvNext = true;
            }
            break;
         case 4:
            if ( !RS.Eof || !RS.Bof )
               RS.MoveLast()
            }
            break;
      }

      // Error Handling
      if ( !RS.BOF || !RS.EOF ) {
         if (RS.EOF && mvNext) {
            RS.MoveLast();
         } else if (RS.EOF) {
            RS.Requery();
         }

         if (RS.BOF && mvPrev) {
            RS.MoveFirst();
         } else if (RS.BOF) {
            RS.Requery();
         }
      }
   } else if (mode == 2) {
      
// Get edit information : Insert, Update, Delete or Cancel
      operate = parseInt( Request.QueryString("operate") );

      switch (operate) {
         case 1:
// Insert
            break;
         case 2:
// Delete
            if (RS.RecordCount > 0) {
               RS.Delete()
               RS.MovePrevious()
               if (RS.RecordCount > 0 && RS.BOF) {
                  RS.MoveFirst()
               }
            }
            break;
         case 3:
// Update
            if ( !RS.EOF && !RS.EOF ) {
               for (i = 0; i < RS.Fields.Count; i++) {
                  fdType = RS(i).Type;
                  if ( RS(i).value == null ) {
                     fdValue = "";
                  } else {
                     fdValue = RS(i).value;
                  }

                  var name = "S" + i
                  var txtVal = Request.Form(name);
                  if ( txtVal == null ) {
                     txtVal = "";
                  }

                  if (Server.URLEnCode(txtVal) != Server.URLEnCode(fdValue)) {
                     if (txtVal == "") {
                        RS(i) = null;
                     } else {
                        switch (fdType) {
                           case 16:
                           case 2:
                           case 3:
                           case 20:
                           case 17:
                           case 18:
                           case 19:
                           case 21:
                           case 4:
                           case 5:
                           case 6:
                           case 14:
                           case 131:
                           case 11:
                              if ( !isNaN( parseInt(txtVal) ) )
                                 RS(i) = txtVal
                              } else {
                                 bErr = true;
                                 msgErr = fdName + " must be a number. Please go back.";
                              }
                              break;
                           default:
                              RS(i) = txtVal
                        }
                     }
                  }
               }
               if ( !bErr ) {
                  RS.Update()
               }
            }
            break;
         case 5:
// Update for addnew
            RS.AddNew();
            for (i = 0; i < RS.Fields.Count; i++) {
               fdType = parseInt( RS(i).type );

               name = "S" + i;
               txtVal = Request.Form(name);
               if ( txtVal == null ) {
                  txtVal = "";
               }

               if ( txtVal != "" ) {
                  switch (fdType) {
                     case 16:
                     case 2:
                     case 3:
                     case 20:
                     case 17:
                     case 18:
                     case 19:
                     case 21:
                     case 4:
                     case 5:
                     case 6:
                     case 14:
                     case 131:
                     case 11:
                        if ( !isNaN( parseInt(txtVal) ) )
                           RS(i) = txtVal
                        } else {
                           bErr = true;
                           msgErr = fdName + " must be a number. Please go back.";
                        }
                        break;
                     default:
                        RS(i) = txtVal
                  }
               }
            }
            if ( !bErr ) {
               RS.Update();
               RS.MoveLast();
            } else {
               RS.CancelUpdate();
            }
         }
      }
%>

<%
   if ( bErr )
      Response.Write( msgErr );
   } else {
%>

<font size="4" face="Arial, Helvetica"> <b>Database Operation Example</b></font><br>
<hr>
<form name=form1 method=Post action="authors.asp">
<CENTER>
<TABLE>
<TR>
<% if (mode == 1) {%>
<TD>
<input type=button name=Browsebt value="Browse Mode" disabled>
<input type=button name=Editbt value="Edit Mode" onClick="ModeClick(2);">
</TD>
<TD width=10> </TD>
<TD>
<input type=button name=MoveFirst value=" |< " onClick="MoveClick(1);">
<input type=button name=MovePrevious value=" < " onClick="MoveClick(2);">
<input type=button name=MoveNext value=" > " onClick="MoveClick(3);">
<input type=button name=MoveLast value=" >| " onClick="MoveClick(4);">
</TD>
</TR>
<% }else if (mode == 2) { %>
<TD>
<input type=button name=Browsebt value="Browse Mode" onClick="ModeClick(1);">
<input type=button name=Editbt value="Edit Mode" disabled>
</TD>
<TD width=10> </TD>
<TD>
<% if (operate == 1) { %>
<input type=button name=Insertbt value="Insert" disabled>
<input type=button name=Deletebt value="Delete" disabled>
<% } else { %>
<input type=button name=Insertbt value="Insert" onClick="OperateClick(1);">
<input type=button name=Deletebt value="Delete" onClick="OperateClick(2);">
<% }
if (operate == 1) { %>

<input type=button name=Updatebt value="Update" onClick="OperateClick(5);">
<% } else { %>
<input type=button name=Updatebt value="Update" onClick="OperateClick(3);">
<% } %>
<input type=button name=Cancelbt value="Cancel" onClick="OperateClick(4);">
</TD>
</TR>
<% } %>
</TABLE>
<BR>
<TABLE>
<% for (i = 0; i < RS.Fields.Count; i++) { %>
<TR>
<TD align=right><strong><%=RS(i).name%>:</strong></TD>
<TD>
<%
   if (mode == 1) {
      if (RS.EOF || RS.EOF) {
%>

<INPUT type=text name=S<%=i%> disabled size=38>
<%
      } else {
         aa = "";
         if ( RS(i).value != null ) {
            aa = RS(i).value.toString();
            pos = aa.indexOf("\"");
            while (pos != -1 ) {
               bb = aa.substring(0, pos) + """
               if ( pos < aa.length - 1)
                  aa = bb + aa.substr( pos + 1);
               } else {
                  aa = bb;
                  pos = aa.indexOf("\"");
               }
            }
%>

<input type=text name=S<%=i%> disabled value="<%=aa%>" size=38>
<%
         }
      } else if (mode == 2) {
         if (RS.BOF || RS.EOF || operate == 1) {
%>

<input type=text name=S<%=i%> size=38>
<%
         } else {
            aa = "";
            if ( RS(i).value != null ) {
               aa = RS(i).value.toString();
               pos = aa.indexOf("\"");
               while (pos != -1 ) {
                  bb = aa.substring(0, pos) + """
                  if ( pos < aa.length - 1)
                     aa = bb + aa.substr( pos + 1);
                  } else {
                     aa = bb;
                     pos = aa.indexOf("\"");
                  }
               }
%>

<input type=text name=S<%=i%> value="<%=aa%>" size=38>
<%
            }
         }
%>

</TD>
</TR>
<%
      }
%>

</TABLE>
</CENTER>
<hr size="1" color="#000000">
<EM>This is a <%=dbms%> database.</EM> <font size="+1">
<center>
<a href="default.asp">Return Home</a>
</center>
</font>
</FORM>
<%
   }
%>

</BODY>
</HTML>


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