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"> </td>
<td width="18"> </td>
<td width="227"> </td>
<td width="44"> </td>
<td width="68"> </td>
<td width="20"> </td>
<td width="79"> </td>
<td width="42"> </td>
<td width="11"> </td>
<td width="49"> </td>
</tr>
<tr>
<td colspan="2">Order Name : </td>
<td><span class="style4"><%=OrderName%></span></td>
<td> </td>
<td> </td>
<td><input type="checkbox" name="checkbox16" value="checkbox"></td>
<td colspan="2">New Client </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Client:</td>
<td><span class="style4"><%=Client%></span></td>
<td> </td>
<td> </td>
<td><input type="checkbox" name="checkbox162" value="checkbox"></td>
<td colspan="2">Existing Client </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Account #:</td>
<td><span class="style4"><%if AccountNo = "" then
%> <%
else
response.write AccountNO End If%></span></td>
<td> </td>
<td> </td>
<td><input type="checkbox" name="checkbox163" value="checkbox"></td>
<td colspan="2">New Account # </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Order Type: </td>
<td><span class="style4"><%=OrderType%></span></td>
<td> </td>
<td> </td>
<td><input type="checkbox" name="checkbox164" value="checkbox"></td>
<td colspan="2">Existing Account # </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Contact:</td>
<td><%ClientContactList(ClientID)%></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Name:</td>
<td> </td>
<td><div id="Name" > </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Address:</td>
<td> </td>
<td><div id="Address" > </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div id="City" > </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div id="abbreviation"> </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><div id="zip"> </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Phone Number:</td>
<td><div id="Phone"> </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Fax Number:</td>
<td><div id="Fax"> </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Email Address:</td>
<td><div id="Email"> </div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="500" border="0" cellpadding="2" cellspacing="0" align="center" >
<tr>
<td colspan="9"> </td>
</tr>
<tr>
<td colspan="9"><span class="style13">Please Check all those that apply.</span> </td>
</tr>
<tr>
<td width="22" class="style10"> </td>
<td width="266" colspan="4" class="style10"> </td>
<td width="4" class="style10"> </td>
<td width="20" class="style10"> </td>
<td width="352" colspan="2" class="style10"> </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"> </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"> </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"> </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"> </td>
<td class="style10"><input type="checkbox" name="checkbox153" value="checkbox"></td>
<td colspan="2" class="style10">Move to account executive for Pre Service & 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 & Newsletter </td>
<td class="style10"> </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"> </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"> </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"> </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"> </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"> </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>