0

I've read through a few threads on here about Classic ASP and Javascript, but can not find anything that is totally helpful.

I'm trying to convert my working vb script into Javascript, but am running into problems.

Here is my code:

<%
//Declare variables
var formdate, jsia, jsga, yvcia, yvcga, query, myDSN, Connect, rs;

//Provider String and DB location
myDSN = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;DATA SOURCE=" & Server.Mappath("/MasterDB.accdb");
//myDSN = "PROVIDER=SQLOLEDB.1;SERVER=myServerAddress;DATABASE=myDataBase;UID=myUserName;PWD=myPassword";

//Collect data from form
formdate = Request.Form("date");
jsia = Request.Form("jsia");
jsga = Request.Form("jsga");
yvcia = Request.Form("yvcia");
yvcga = Request.Form("yvcga");

//SQL for Query
query = "SELECT * FROM ATTENDANCE;";

//Create and open connection to database
Connect = Server.CreateObject("ADODB.Connection");
Connect.Open myDSN;

//Create recordset
rs = Server.CreateObject("ADODB.recordset");

//Open recordset run query in database
rs.Open query, Connect, adOpenStatic, adLockOptimistic;

rs.AddNew
    rs("Attendance_Date") = formdate;
    rs("JS_Individuals") = jsia;
    rs("JS_Groups") = jsga;
    rs("YVC_Individuals") = yvcia;
    rs("YVC_Groups") = yvcga;
rs.Update;

//Display message
Response.Write("<h1>Your form has been received. Thank you.</h1>");

//Close recordset and database connection
rs.close;
Connect.close;
%>

Any tips or documentation I can read on this? I've checked w3schools but they only cover VB script for Classic ASP.

Thanks!

10
  • 2
    "I'm trying to convert my working vb script into Javascript" - Why?? Commented Jun 22, 2015 at 2:24
  • I've already written javascript to do form check on the client side, I wanted to add the same functionality to my serverside script. VBScript has limitations, such as not having Try Catch capabilities. Commented Jun 22, 2015 at 2:30
  • 2
    Okay, fair enough. However, questions like "I can't find documentation" and "please rewrite this program for me in a different language" are off-topic on this site. There is extensive documentation on JScript on the Microsoft pages. If you have a particular problem or question, you are welcome to ask it here. Otherwise this question, as it currently is, is out of scope for StackOverflow, sorry. Commented Jun 22, 2015 at 2:35
  • 2
    Oh, and last tip: VBScript does have error handling. And ASP does support running both VBScript and JScript on the same page. So maybe you'll be better off leaving your working VBS code alone and set up a <script runat="server" language="jscript"> section to host your user input checking functions. There is a caveat about running both languages on the same page, but it probably does not apply to your situation. Commented Jun 22, 2015 at 2:43
  • 1
    Note that the language that classic ASP pages run is officially called "JScript". Search results might improve by using the proper keyword. In any case, if your JS functions are written in a re-usable fashion then running the same .js file on the client and on the server should be relatively unproblematic. Commented Jun 22, 2015 at 2:49

1 Answer 1

1
<%@ LANGUAGE=JavaScript%>

<%
//Declare variables
var formdate, jsia, jsga, yvcia, yvcga, query, myDSN, Connect, rs;

//Provider String and DB location
 myDSN = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;DATA SOURCE=" +
 Server.Mappath("/MasterDB.accdb");

//Collect data from form
formdate = Request.Form("date");
jsia = Request.Form("jsia");
jsga = Request.Form("jsga");
yvcia = Request.Form("yvcia");
yvcga = Request.Form("yvcga");

var adOpenStatic = 3;
var adLockOptimistic = 3;

//SQL for Query
query = "SELECT * FROM ATTENDANCE;";

//Create and open connection to database
Connect = Server.CreateObject("ADODB.Connection");
Connect.Open(myDSN);

//Create recordset
rs = Server.CreateObject("ADODB.recordset");

//Open recordset run query in database
rs.Open (query, Connect, adOpenStatic, adLockOptimistic);
var fields=Array("Attendance_Date","JS_Individuals","JS_Groups","YVC_Individuals", "YVC_Groups");
var values=Array(formdate,jsia,jsga,yvcia,yvcga);

rs.AddNew(fields,values);
rs.Update();

//Display message
Response.Write("<h1>Your form has been received. Thank you.</h1>");

//Close recordset and database connection
rs.close;
Connect.close;
%>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.