Microsoft VBScript & JScript Help

Discussion in 'Javascript' started by JNariss@gmail.com, Mar 9, 2006.

  1. Guest

    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
     
    , Mar 9, 2006
    #1
    1. Advertising

  2. Guest

    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, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,315
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,434
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. Andrew Wan

    HELP: ASP JScript & VBScript interoperability

    Andrew Wan, Jun 15, 2007, in forum: ASP General
    Replies:
    1
    Views:
    139
    Anthony Jones
    Jun 15, 2007
  4. John Bentley
    Replies:
    14
    Views:
    385
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    376
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page