• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Pass ASP Variable to Javascript with href

I am working on a custom built ASP 3.0 and SQL site that is being used to track calls and issues within our department.

I am working on our reports page and have generated a bar graph that dynamically shows the volume of calls each client generates.  I did this by passing an ASP variable into a Javascript program that creates the graph.  What I would like to do now is make the clients name within the graph a hyperlink to a detail report page that would query all of that clients tickets based on a querystring.  I know how to do all of that except for getting the Javascript to accept the anchor.

I tried modifying the code, which resulted in the graph not rendering at all (which was half what I expected to happen but, was the only thing I could think of at the time).  The modification I made is shown at the end of the code section
'Client Totals - ALL
	Dim RSClientTotals, SQLClientTotals
	Set RSClientTotals = Server.CreateObject("ADODB.Recordset")
	SQLClientTotals = "SELECT COUNT(ClientEmplID) as TicketTotal, ClientLName, ClientFName FROM ticketinformation GROUP BY ClientLName, ClientFName ORDER BY ClientLName, ClientFName"
	Set RSClientTotals = MyConn.Execute(SQLClientTotals)

	'Create Graph Values
		Dim ClientTotals, ClientLabels, iRecClientTotals 
		iRecClientTotals = 0
		If NOT RSClientTotals.EOF Then
			While NOT RSClientTotals.EOF
				If  iRecClientTotals = 0 Then
					ClientTotals = RSClientTotals("TicketTotal")
					ClientLabels = RSClientTotals("ClientLName")
					ClientTotals = ClientTotals & "," & RSClientTotals("TicketTotal")
					ClientLabels = ClientLabels & "," & RSClientTotals("ClientLName")
				End If			
			iRecClientTotals = iRecClientTotals + 1
		End If
		ClientTotals = """" & ClientTotals & """"
		ClientLabels = """" & ClientLabels & """"
		'response.write ClientTotals
		'response.write ClientLabels
<script type="text/javascript"> 
var showValues, barWidth, barLength, labelSize, absValuesSize, percValuesSize, graphPadding, graphBGColor, graphBorder, barColors
var barBGColor, barBorder, labelColor, labelBGColor, labelBorder, absValuesColor, absValuesBGColor, absValuesBorder
showValues = 1;
barWidth = 20;
barLength = 1;
labelSize = 12;
absValuesSize = 12;
percValuesSize = 12;
graphPadding = 10;
graphBGColor = "#CACCB4";
graphBorder = "1px solid #DEDECF";
barColors = "#898B5E";
barBGColor = "#CACCB4";
barBorder = "2px outset #DEDECF";
labelColor = "#000000";
labelBGColor = "#DEDECF";
labelBorder = "2px groove #DEDECF";
absValuesColor = "#000000";
absValuesBGColor = "#CACCB4";
absValuesBorder = "2px groove #CACCB4";

				<td valign="top">
					<table border="1">
							<td align="center" style="font-weight:bold" colspan="2">TODAY</td>							
							<td align="center" style="font-weight:bold">Cases by Tech</td>
							<td align="center" style="font-weight:bold">Cases by Status</td>							
							<td valign="top">
								<script type="text/javascript"> <!--
									var TicketValuesT
									var TechLabelsT						
									TicketValuesT = <%=TicketValuesT%>
									TechLabelsT = <%=TechLabelsT%>
									var graph = new BAR_GRAPH("hBar");
									graph.values = TicketValuesT;
									graph.labels = TechLabelsT;
									graph.showValues = showValues;
									graph.barWidth = barWidth;
									graph.barLength = barLength;
									graph.labelSize = labelSize;
									graph.absValuesSize = absValuesSize;
									graph.percValuesSize = percValuesSize;
									graph.graphPadding = graphPadding;
									graph.graphBGColor = graphBGColor;
									graph.graphBorder = graphBorder;
									graph.barColors = barColors;
									graph.barBGColor = barBGColor;
									graph.barBorder = barBorder;
									graph.labelColor = labelColor;
									graph.labelBGColor = labelBGColor;
									graph.labelBorder = labelBorder;
									graph.absValuesColor = absValuesColor;
									graph.absValuesBGColor = absValuesBGColor;
									graph.absValuesBorder = absValuesBorder;


If  iRecClientTotals = 0 Then

ClientTotals = RSClientTotals("TicketTotal")
ClientLabels = "<a href=""#"">" & RSClientTotals("ClientLName") & "</a>"


ClientTotals = ClientTotals & "," & RSClientTotals("TicketTotal")
ClientLabels = ClientLabels & "," & "<a href=""#"">" & RSClientTotals("ClientLName") & "</a>"

End If

Open in new window

  • 2
1 Solution
I think you need to escape your quotation marks so they are literally applied in your code.

You can't send something like this:

link="some text here" + "some "quote" marks"

that's a syntax error. You have to do this:

link="some text here" +  "some \"quote\" marks"

Preceding your quotations with a reverse slash (\) escapes them so that whatever character follows is output rather than interpreted.

LouSch7Author Commented:

I attempted to use your escape suggestion as shown in the attached code...It resulted in the following error:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/test/members/Reports.asp, line 314, column 47
ClientLabels = ClientLabels & "," & "<a href=\"#\">" & RSClientTotals("ClientLName") & "</a>"
ClientLabels = ClientLabels & "," & "<a href=\"#\">" & RSClientTotals("ClientLName") & "</a>"

Open in new window

oops...my bad. I was thinking in terms of every other programming language OTHER than VB.

I think in VB you have to use three double quotation marks to get a single double quote in the output.

ClientLabels = ClientLabels & "," & "<a href="""#""">" & RSClientTotals("ClientLName") & "</a>"
Om PrakashCommented:
3 quotes will give uou an error. Only 2 double quotes are sufficient:

ClientLabels = ClientLabels & ",<a href=""#"">" & RSClientTotals("ClientLName") & "</a>"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now