By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Microsoft VBScript & JScript Help

P: n/a
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|Transfe rFrom|value|TransferTo|value|TypeOfEmployee|value| TempNumberOfDays|value|EmployeeName|value|Title|va lue|PayNumber|value|Department|value|StartDate|val ue|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|val ue|Headset|value|HeadsetOptions|value|OmitLongDist ance|value|OmitInternationalDialing|value|Building Access|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,''|Type OfEmployee|',none,''|TempNumberOfDays|',none,''|Em ployeeName|',none,''|Title|',none,''|PayNumber|',n one,''|Department|',none,''|StartDate|',none,NULL| EndDate|',none,NULL|ManagersName|',none,''|Manager sPhone|',none,''|Location|',none,''|Telecommunicat ionDevice|',none,''|PCType|',none,''|MonitorType|' ,none,''|PrinterType|',none,''|ARNumber|',none,''| PCSerialNumber|',none,''|AssetTag|',none,''|Wirele ssNic|none,none,NULL|RASVPN|none,none,NULL|BPCS|no ne,1,0|LogPro|none,1,0|Payroll|none,1,0|Additional SoftwareRequests|',none,''|Headset|none,1,0|Headse tOptions|',none,''|OmitLongDistance|none,1,0|OmitI nternationalDialing|none,1,0|BuildingAccess|none,1 ,0|CommentsNotes|',none,''|RequestedBy|',none,''|D ate|',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[i]));
}

// 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[i];
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

Mar 9 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Mar 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.