Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2007, 03:47 PM
Registered User
 
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mperry
Default Passing Variables from Javascript/AJAX to VBScrip

I have one asp page that has a form and on it. The form gets an orderID # and uses that to query the database to get basic order information . I show the the results in a table. Next the user is able to choose drom checkboxes what they want. Lastly a drop down box (which pulls all contacts for the order) is a FUNCTION on the same page. I have an onchange event that runs a Javascript of course. The javascript uses some AJAX which instantly displays additional information on the contact. So when a user selects the contact in the drop down menu, it automatically populates additional information on that contact quickly. Ok, all this works fine.

Now ... I have a print button. When clicking this button the form is submitted back to itself (postback) with the new variables. When posting back I pass a hard varibale through the query string to signify this is the print version. I then use coniditional logic to display what I want based on the printed version.

Here is where the problem lies. When I get the printed version everything shows correctly except the contact informaton (chosen from the drop down) as well as all the other contact information. I cannot get any dynamic variables to pass through. I need to know what I am doing wrong and a better approach on doing this.

My server side code is VBSCRIPT, and I am also utilizing Javascript and some AJAX.

Here is the complete piece of code that I am working from:

<%@ Language = VBScript %>
<%Option Explicit%>

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/includes/mainMenu.css"/>

            <% If Printversion <> "Yes" Then%>
                <script type="text/javascript" src="../includes/menuDD2.js"></script>
                <script type="text/javascript" src="../includes/AJAXJavascript.js"></script>
            <%End If%>

    <Script LANGUAGE="Javascript">
        //Function for printing the document
        function confirmprintnon()
        {
                window.focus();
                window.print();
                return true;
            }


        </Script>

    </head>
            <style type="text/css">
<!--
.style4 {
        color:#0000FF
         }
.style10 {color: #FF0000; font-size: xx-small; }
.style13 {font-weight: bold}
-->
            </style>


<%
        '---------------------------------------------------------------------------
        'Open all connections and com objects for the page
        '---------------------------------------------------------------------------
        Dim cn

            Set cn = Server.CreateObject("ADODB.Connection")
            cn.Open MCCIConnectionString


        Dim ClientID
        Dim Client
        Dim Address
        Dim City
        Dim Abbreviation
        Dim zip
        Dim PhoneAreaCode
        Dim phone
        Dim FaxAreaCode
        Dim Fax
        Dim OrderID
        Dim OrderTypeID
        Dim OrderType
        Dim OrderName
        Dim AccountNo
        Dim SQL
        Dim checklistRS
        Dim IndividualPageTitle
        Dim PhonePrefix
        Dim FaxPrefix
        Dim Printversion
        Dim ClientContacts
        Dim clientContacts2


        OrderID = Trim(Request("OrderID"))
        Printversion = Trim(Request("Printversion"))

' If Printversion = "Yes" then
' ClientContacts = Trim(Request("ClientContacts"))
' response.write ClientContacts
' else
' End If


        IndividualPageTitle = "New Contract CheckList" %>

        <body <%If Printversion = "Yes" Then%> onload='confirmprintnon();' <%End If%> >

        <%If Printversion <> "Yes" Then%>



        <%Else%>
            <h2 align="center">New Contract Checklist</h2>
                <%End If%> <%



        'Get Order ID from OrderPage Query String
            OrderID = Trim(Request("OrderID"))

        SQL = " "
        SQL = SQL & " SELECT c.ClientID, c.Client, c.Address, c.City, s.Abbreviation, c.zip, c.PhoneAreaCode, c.phone,"
        SQL = SQL & " c.FaxAreaCode, c.Fax, o.OrderID, o.OrderTypeID, ot.OrderType, o.OrderName, o.AccountNo "
        SQL = SQL & " FROM Mcci_Clients c, Mcci_Orders o, Mcci_States s, Mcci_OrderTypes ot "
        SQL = SQL & " WHERE c.ClientID = o.ClientID "
        SQL = SQL & " AND c.stateID = s.StateID "
        SQL = SQL & " AND o.orderTypeID = ot.orderTypeID "
        SQL = SQL & " AND o.OrderID = " & OrderID
        SQL = SQL & " ORDER by c.ClientID ASC "

            Set checklistRS = Server.CreateObject("ADODB.Recordset")
                checklistRS.Open SQL,cn

            ClientID = checklistRS("ClientID")
            Client = checklistRS("Client")
            Address = checklistRS("Address")
            City = checklistRS("City")
            Abbreviation = checklistRS("Abbreviation")
            zip = checklistRS("zip")
            PhoneAreaCode = checklistRS("PhoneAreaCode")
            PhonePrefix = left(checklistRS("Phone"),3)
            phone = right(checklistRS("Phone"),4)
            FaxAreaCode = checklistRS("FaxAreaCode")
            FaxPrefix = left(checklistRS("Fax"),3)
            Fax = right(checklistRS("Fax"),4)
            OrderID = checklistRS("OrderID")
            OrderTypeID = checklistRS("OrderTypeID")
            OrderType = checklistRS("OrderType")
            OrderName = checklistRS("OrderName")
            AccountNo = checklistRS("AccountNo")

%>

<form action="Checklist.asp" id="Checklist" method="post" >
    <table width="720" border="0" cellpadding="2" cellspacing="0" align="center" >
    <tr>
        <td colspan="10"><div align="center"><strong>New Contract Checklist</strong></div></td>
    </tr>
        <tr>
        <td width="100">&nbsp;</td>
        <td width="18">&nbsp;</td>
        <td width="227">&nbsp;</td>
        <td width="44">&nbsp;</td>
        <td width="68">&nbsp;</td>
        <td width="20">&nbsp;</td>
        <td width="79">&nbsp;</td>
        <td width="42">&nbsp;</td>
        <td width="11">&nbsp;</td>
        <td width="49">&nbsp;</td>
    </tr>
        <tr>
          <td colspan="2">Order Name : </td>
          <td><span class="style4"><%=OrderName%></span></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox16" value="checkbox"></td>
          <td colspan="2">New Client </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Client:</td>
          <td><span class="style4"><%=Client%></span></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox162" value="checkbox"></td>
          <td colspan="2">Existing Client </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Account #:</td>
          <td><span class="style4"><%if AccountNo = "" then
              %>&nbsp;<%
                else
                    response.write AccountNO End If%></span></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox163" value="checkbox"></td>
          <td colspan="2">New Account # </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Order Type: </td>
          <td><span class="style4"><%=OrderType%></span></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="checkbox164" value="checkbox"></td>
          <td colspan="2">Existing Account # </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Contact:</td>
          <td><%ClientContactList(ClientID)%></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>Name:</td>
          <td>&nbsp;</td>
          <td><div id="Name" >&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>Address:</td>
          <td>&nbsp;</td>
          <td><div id="Address" >&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><div id="City" >&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><div id="abbreviation">&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><div id="zip">&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Phone Number:</td>
          <td><div id="Phone">&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Fax Number:</td>
          <td><div id="Fax">&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
        <tr>
          <td colspan="2">Email Address:</td>
          <td><div id="Email">&nbsp;</div></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
  </tr>
</table>




        <table width="500" border="0" cellpadding="2" cellspacing="0" align="center" >
        <tr>
          <td colspan="9">&nbsp;</td>
          </tr>
        <tr>
          <td colspan="9"><span class="style13">Please Check all those that apply.</span> </td>
          </tr>
        <tr>
          <td width="22" class="style10">&nbsp;</td>
          <td width="266" colspan="4" class="style10">&nbsp;</td>
          <td width="4" class="style10">&nbsp;</td>
          <td width="20" class="style10">&nbsp;</td>
          <td width="352" colspan="2" class="style10">&nbsp;</td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox" value="checkbox"></td>
          <td colspan="4" class="style10">Assign Account # in MCC Accounts </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox142" value="checkbox"></td>
          <td colspan="2" class="style10">Enter Order Into BIS</td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox2" value="checkbox"></td>
          <td colspan="4" class="style10">If new contract, email account info to Melissa and Janice </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox14" value="checkbox"></td>
          <td colspan="2" class="style10">Put Purchase Order # into BIS </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox3" value="checkbox"></td>
          <td colspan="4" class="style10">Update Customer List in Laserfiche </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox15" value="checkbox"></td>
          <td colspan="2" class="style10">Move to account executive for follow up / Pre Install for installation </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox152" value="checkbox"></td>
          <td colspan="4" class="style10">Scan contract into Laserfiche </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox153" value="checkbox"></td>
          <td colspan="2" class="style10">Move to account executive for Pre Service &amp; Krysten for pending </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox4" value="checkbox"></td>
          <td colspan="4" class="style10">Update BIS - User &amp; Newsletter </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox13" value="checkbox"></td>
          <td colspan="2" class="style10">Move to Christie for billing </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox5" value="checkbox"></td>
          <td colspan="4" class="style10">Announce new contract </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox12" value="checkbox"></td>
          <td colspan="2" class="style10">Move to Doug for Assignment of PM </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox6" value="checkbox"></td>
          <td colspan="4" class="style10"><p>Set up file in LF ( if needed) </p> </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox11" value="checkbox"></td>
          <td colspan="2" class="style10">Send Pre-Install (LF or MA) to Account Executive </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox7" value="checkbox"></td>
          <td colspan="4" class="style10">Scan contract into LF </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox10" value="checkbox"></td>
          <td colspan="2" class="style10">Send Client Password and copy of signed contract </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox8" value="checkbox"></td>
          <td colspan="4" class="style10">Add to Contract Received (F drive, executive, Contracts Report) </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox9" value="checkbox"></td>
          <td colspan="2" class="style10">Snapshot email and announcement </td>
          </tr>
        <tr>
          <td class="style10"><input type="checkbox" name="checkbox93" value="checkbox"></td>
          <td colspan="4" class="style10">Add to google map </td>
          <td class="style10">&nbsp;</td>
          <td class="style10"><input type="checkbox" name="checkbox92" value="checkbox"></td>
          <td colspan="2" class="style10">Add client's products to Product Support Report (F drive executive) </td>
          </tr>
    </table>



    <input name="button" type="button" onClick="window.location='checklist.asp?OrderId=<% =OrderId%>&Printversion=Yes&ClientContacts=<%=Clie ntContacts%>&'" value="Print Order">
        <input type="hidden" name="ClientContacts" value="<%=ClientContacts%>">

</form>

        </html>

</body><%


'--------------------------------------------------------------------------------------------------------
'SubClients SubRoutine
'--------------------------------------------------------------------------------------------------------
Sub ClientContactList(ClientID)
    Dim SQL
    Dim ClientRS

    'Populates Contact Box with all the Contacts for the client

    SQL = " SELECT co.FName +' '+ co.LName as Name, cc.ContactID, cl.ClientID "
    SQL = SQL & " FROM Mcci_Clients cl, Mcci_ClientContacts cc, Mcci_Contacts co "
    SQL = SQL & " WHERE cl.ClientID = cc.ClientID "
    SQL = SQL & " AND cc.ContactID = co.ContactID "
    SQL = SQL & " AND cl.ClientID = " & clientID
    SQL = SQL & " Order by cl.Client "

%>
    <select name="ClientContacts" id="ClientContacts" onChange="fillInContactList(this)" >
        <option value=""></option>
<%
    Set ClientRS = Server.CreateObject("ADODB.Recordset")
        ClientRS.Open SQL,cn
        Do While Not ClientRS.EOF
%>

    <option value="<%=ClientRS("ContactID")%>" > <%=ClientRS("Name")%> </option>

<%
            ClientRS.MoveNext
        Loop
        ClientRS.Close
    Set ClientRS = Nothing
%>
    </select>
<%
End Sub %>

<script language="javascript">

function fillInContactList(selectObj){
        //document.write selectObj.options[selectObj.selectedIndex].value

        //Only talk to the server if the user choose a Contact to display.

        //The Entire Select Options Box is encapsulated within the selectObj box. The index refers to the entier index of
        //items that are showing in the box. Then the value that was selected is recorded.

        if(selectObj.options[selectObj.selectedIndex].value != "")
        {

            var sqlString = " SELECT co.FName +' '+ co.LName as Name, cc.ContactID, cl.clientID, co.Title, co.PhoneAreaCode, co.Phone, co.FaxAreaCode, co.Fax, co.Email, a.address, a.city, s.abbreviation, a.zip ";
            sqlString += " FROM Mcci_Clients cl, Mcci_ClientContacts cc, Mcci_Contacts co, Mcci_ContactAddresses ca, Mcci_Addresses a, Mcci_States s ";
            sqlString += " WHERE cl.ClientID = cc.ClientID ";
            sqlString += " AND cc.ContactID = co.ContactID ";
            sqlString += " AND co.ContactID = ca.ContactID ";
            sqlString += " AND ca.AddressID = a.AddressID ";
            sqlString += " AND a.stateID = s.StateID ";
            sqlString += " AND cc.ContactID = " + selectObj.options[selectObj.selectedIndex].value + "";

            //Set up and use the psuedo AJAX functions to get a recordset as an XML object
            var reqXml = getNewRequestXML();
            var connString = "";

                setUpSqlQuery(reqXml, sqlString , connString);

            //Get the response from the server.
            var xmlHttpResponse = interactWithUrl("../includes/AJAXbackEnd.asp", reqXml);

            //Get the response as an xmlDom document object.
            var rsAsXmlObj = xmlHttpResponse.responseXML;
            //alert(xmlHttpResponse.responseText);

            //Get first record from the RS.
            var rowObj = getRowObj(rsAsXmlObj,0)

            document.getElementById("Name").firstChild.nodeVal ue = rowObj["Name"] ;
            document.getElementById("Address").firstChild.node Value = rowObj["address"] ;
            document.getElementById("City").firstChild.nodeVal ue = rowObj["city"] ;
            document.getElementById("abbreviation").firstChild .nodeValue = rowObj["abbreviation"] ;
            document.getElementById("zip").firstChild.nodeValu e = rowObj["zip"] ;
            document.getElementById("Phone").firstChild.nodeVa lue = rowObj["PhoneAreaCode"] + ")" + rowObj["Phone"] ;
            document.getElementById("Fax").firstChild.nodeValu e = rowObj["FaxAreaCode"] + ")" + rowObj["Fax"] ;
            document.getElementById("Email").firstChild.nodeVa lue = rowObj["Email"] ;

        } //If the user chose the blank option, clear out the related fields.
        else
        {
            document.getElementById("Name").firstChild.nodeVal ue = " " ;
            document.getElementById("Address").firstChild.node Value = " " ;
            document.getElementById("City").firstChild.nodeVal ue = " " ;
            document.getElementById("zip").firstChild.nodeValu e = " " ;
            document.getElementById("PhoneAreaCode").firstChil d.nodeValue = " " ;
            document.getElementById("Fax").firstChild.nodeValu e = " " ;
            document.getElementById("Email").firstChild.nodeVa lue = " " ;

        }

    }
</script>
</body>







 
Old October 19th, 2007, 11:42 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you made any tests to see what values are available?
I suggest that you put together a little method that outputs your request variables. You can print these out at the top or bottom of your page, whatever you like. I usually have a little include file that contains various debugging utilities that does things like that. In fact, most of my debug utils are in a class which makes it very easy to include a fair amount of debugging and tracing into any page, and I can switch it all on or off by setting a flag.

Since your input button onClick causes a "get" rather than a "post", you aren't going to be getting any of your form variables. You have hardcoded the onClick to ignore anything that has been done on the page after the page is loaded.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old October 22nd, 2007, 08:17 AM
Registered User
 
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mperry
Default

Thank you so much for your response to my question. It was very helpful. I started a little box of tools and will continue to add more tools to the box.

I did do some tests and saw that no variables were passing through. I changed the form element to POST instead of GET. But the problem was

The onClick event was stopping anything else from passing through. Because it was hard-coded, everything was getting cleared when the page was posting back to itself.

What I did was stop the post back all together and put the print command directly on the print button

Thank you for the direction on this.





Since your input button onClick causes a "get" rather than a "post", you aren't going to be getting any of your form variables. You have hardcoded the onClick to ignore anything that has been done on the page after the page is loaded.

 
Old November 12th, 2007, 03:29 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Glad to be of help.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Javascript Variables to Asp.Net? Grumpy ASP.NET 2.0 Basics 4 September 8th, 2006 11:52 PM
passing array from combo box thru ajax amorphic8 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 10th, 2006 03:23 AM
Passing Variables CMOS Classic ASP Basics 2 January 22nd, 2006 07:38 PM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
Passing variables jesseleon Access VBA 4 October 24th, 2003 01:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.