Microsoft VBScript & JScript Help

J

JNariss

Hello,

I have created a connection to my Access database with Dreamweaver and
made a simple form with 4 fields.

The code behind this form was/is:

<%@LANGUAGE="VBCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/Connections/EmployeeStatusChange.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables

if (String(Request("MM_insert")) == "form1") {

var MM_editConnection = MM_ITESC_STRING;
var MM_editTable = "MacForm";
var MM_editRedirectUrl = "SuggestionConf.htm";
var MM_fieldsStr =
"NewHire|value|Change|value|Transfer|value|TransferFrom|value|TransferTo|value|TypeOfEmployee|value|TempNumberOfDays|value|EmployeeName|value|Title|value|PayNumber|value|Department|value|StartDate|value|EndDate|value|ManagersName|value|ManagersPhone|value|Location|value|TelecommunicationDevice|value|PCType|value|MonitorType|value|PrinterType|value|ARNumber|value|PCSerialNumber|value|AssetTag|value|WirelessNic|value|RASVPN|value|BPCS|value|LogPro|value|Payroll|value|AdditionalSoftwareRequests|value|Headset|value|HeadsetOptions|value|OmitLongDistance|value|OmitInternationalDialing|value|BuildingAccess|value|CommentsNotes|value|RequestedBy|value|Date|value";
var MM_columnsStr =
"NewHire|none,1,0|Change|none,1,0|Transfer|none,1,0|TransferFrom|',none,''|TransferTo|',none,''|TypeOfEmployee|',none,''|TempNumberOfDays|',none,''|EmployeeName|',none,''|Title|',none,''|PayNumber|',none,''|Department|',none,''|StartDate|',none,NULL|EndDate|',none,NULL|ManagersName|',none,''|ManagersPhone|',none,''|Location|',none,''|TelecommunicationDevice|',none,''|PCType|',none,''|MonitorType|',none,''|PrinterType|',none,''|ARNumber|',none,''|PCSerialNumber|',none,''|AssetTag|',none,''|WirelessNic|none,none,NULL|RASVPN|none,none,NULL|BPCS|none,1,0|LogPro|none,1,0|Payroll|none,1,0|AdditionalSoftwareRequests|',none,''|Headset|none,1,0|HeadsetOptions|',none,''|OmitLongDistance|none,1,0|OmitInternationalDialing|none,1,0|BuildingAccess|none,1,0|CommentsNotes|',none,''|RequestedBy|',none,''|Date|',none,NULL";

// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");

// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields));
}

// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString &&
Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') ==
-1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined") {

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] :
"";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] :
"";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] :
"";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "") + MM_columns;
MM_dbValues += ((i != 0) ? "," : "") + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues
+ ") values (" + MM_dbValues + ")";

if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}

}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post"
action="<%=MM_editAction%>">
<p>
<label>Employee Name
<input name="EmployeeName" type="text" id="EmployeeName" />
</label>
</p>
<p>
<label>Pay Number
<input name="PayNumber" type="text" id="PayNumber" />
</label>
</p>
<p>
<label>Location
<input name="Location" type="text" id="Location" />
</label>
</p>
<p>
<label>Requested By
<input name="RequestedBy" type="text" id="RequestedBy" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>

__________________________________________________________________________

But when I go to "preview" this form in a browser I get the following
error:

Microsoft VBScript complilation error '800a0401'
Expected end of statement
/ITEmployeeStatusChangeForm.asp, line 7

var MM_editAction = Request.ServerVariables("SCRIPT_NAME");


So I have figured out that the code must be written in JScript and NOT
VBScript b/c if I change the first line in the code from
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> To <%@LANGUAGE="JSCRIPT"
CODEPAGE="1252"%> I can see my form!!!

I must be on to something but hold your horses and get ready for what
happens next:

If I fill in the 4 basic fields on this form and hit the submit button
then viola........all my information is submitted somewhere and to
someone in the WWW but it sure as hell is not going into my database.

Can someone perhaps see what is happening to this?? I have a
connections folder in my database which includes the "include" file of
information regarding the connction to the DSN. The code behind this
file is as follows:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/ITESC.asp" -->
<%
' FileName="Connection_odbc_conn_dsn.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="false"
' Catalog=""
' Schema=""
Dim MM_ITESC_STRING
MM_ITESC_STRING = "dsn=EmployeeStatusChange;"
%>

But I also notice if I leave codes as is then they are generating 2
scripts. The include is in VB and the form is in JS.

Well I thought this post could be a start and perhaps someone can see
what I can't and help me to figure this out!!! I find it hard to
believe that creating a form and submitting it to a database is this
difficult but I have been working on this for over 2 weeks now and
still have nothing to show for it but a huge folder of "how to do this
and that's" that haven't explained very much!!!

Any help is much appreciated.
Thanks,
Justine
 
J

JNariss

Well I still haven't figured anything out. But I did do a couple
changes and am now receiving the following error when I try to view my
form in a browser window:

Microsoft JScript compilation error '800a03ec'

Expected ';'

/Connections/ITESC.asp, line 8

Dim MM_ITESC_STRING
----^



The include file code is:
<%
FileName="Connection_odbc_conn_dsn.asp"
Type="ADO"
DesigntimeType="ADO"
HTTP="false"
Catalog=""
Schema=""
Dim MM_ITESC_STRING
MM_ITESC_STRING = "dsn=EmployeeStatusChange;"
'%>

So I am guessing by the error that it is talking about the code in my
include file b/c it points to the line: Dim MM_ITESC_STRING as line 8
and line 8 in my form is:
<%@LANGUAGE="JSCRIPT" CODEPAGE="1252"%>
<!--#include virtual="/Connections/ITESC.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

The line: if (Request.QueryString) {



Can anyone help me out here?
Thanks,
Justine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top