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

<%@ Language=JScript %>
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor=Lavender>
<%
bErr = false;
mvNext = false;
mvPrev = false;

if ( Request.Form("ticker").count > 0 ) {
   Session("webRd") = Server.CreateObject("ADODB.RECORDSET");
   Session("webRd").ActiveConnection = Session("webConn");
   Session("webRd").CursorLocation = 3;
   Session("webRd").CursorType = 2;
   Session("webRd").LockType = 2;
   Session("webRd").Source = "SELECT * FROM " + Request.Form("ticker");
   Session("webRd").Open();
}

RS = Session("webRd");

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();
      }
   }

   //'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 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;
            }

            name = "S" + i;
            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.";
                     }
                  default:
                     RS(i) = txtVal;
                  }
               }
            }
         }
         if ( !bErr ) {
            RS.Update();
         }
      }
      break;
   case 5: // Update for addnew
      RS.AddNew();
      var needUpdate = false;
      for (i = 0; i < RS.Fields.Count; i++) {
         fdType = parseInt( RS(i).type );
         name = "S" + i.toString();
         txtVal = Request.Form(name);
         if ( txtVal == null ) {
            txtVal = "";
         }
         if ( txtVal != "" ) {
            needUpdate = true;
            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 == false && needUpdate == true) {
         RS.Update();
         RS.MoveLast();
      } else {
         RS.CancelUpdate();
      }
   }
}
%>

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

<form name=form1 Method=Post Action="opentb.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></CENTER>

   <TABLE border=0 width=100%>   
<%   for (i = 0; i < RS.Fields.Count; i++) {
      fd = RS.Fields.Item(i);
      if ( i % 2 == 0 ) {%>
      <TR>
<%      }%>
         <TD width=20% align=center><strong><%=fd.Name%>:</strong></TD>
         <TD width=30%>
<%      if (mode == 1) {
         if (RS.EOF || RS.EOF) {
            if (fd.type == 201 || fd.type == 203) {%>
               <TEXTAREA name=S<%=i%> disabled cols=22 rows=4 width=200 style="width:200"></TEXTAREA>
<%            } else {%>
               <INPUT name=S<%=i%> disabled size=26 value="">
<%            }
         } else {
            if (fd.type == 201 || fd.type == 203) {%>
               <TEXTAREA name=S<%=i%> disabled cols=22 rows=4 width=200 style="width:200"><%=fd.value%></TEXTAREA>
<%            } else {
               if (fd.value == null ) {%>
               <INPUT name=S<%=i%> disabled size=26 value="">
<%               }else if (fd.type == 129 || fd.type == 200 || fd.type == 130 || fd.type == 202) {
                  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 name=S<%=i%> disabled size=26 value="<%=aa%>">
<%               } else {%>
               <INPUT name=S<%=i%> disabled size=26 value="<%=fd.value%>">
<%               }
            }
         }
      }else if (mode == 2) {
         if (RS.BOF || RS.EOF || operate == 1) {
            if (fd.type == 201 || fd.type == 203) {%>
            <TEXTAREA name=S<%=i%> cols=22 rows=4 width=200 style="width:200"></TEXTAREA>
<%            } else {%>
            <INPUT name=S<%=i%> size=26 value="">
<%            }
         } else {
            if (fd.type == 201 || fd.type == 203) {%>
            <TEXTAREA name=S<%=i%> cols=22 rows=4 width=200 style="width:200"><%=fd.value%></TEXTAREA>
<%            } else {
               if ( fd.value == null ) {%>
               <INPUT name=S<%=i%> size=26 value="">
<%               }else if (fd.type == 129 || fd.type == 200 || fd.type == 130 || fd.type == 202) {
                  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 name=S<%=i%> size=26 value="<%=aa%>">
<%               } else {%>
               <INPUT name=S<%=i%> size=26 value="<%=fd.value%>">
<%               }
            }
         }
      }%>
         </TD>
<%      if (i % 2 == 1) {%>
         </TR>
<%      }
   }%>

<%   if ( i % 2 == 1 ) {%>
      <TD width=20%> </TD><TD width=30%> </TD></TR>
<%   }%> 
   </TABLE>
</FORM>

<input type=hidden name=InsertInf size=4 value="<%=%>">

<%}%>

<Script Language = "JavaScript">
function MoveClick(option){
   document.form1.action = "opentb.asp?mode=1&direction=" + option;
   document.form1.submit();
}

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

function OperateClick(option) {
   document.form1.action = "opentb.asp?mode=2&operate=" + option;
   document.form1.submit();
}
</Script>

</BODY>
</HTML>

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