Forums
This topic is locked
Hyperlink and new window to reponse.write field
Posted 31 Mar 2003 16:25:31
1
has voted
31 Mar 2003 16:25:31 Sze-Wai Lai posted:
Hi, i don't know if anyone can help, but I'd essentially like to be able to allow users to download a job application form from our servers.
I have this page (pre written by someone else) linking to a MS SQL database. The field WelshJobApp contains an http address, like www.rnid.org.uk/JobVacancies/jobref1041.doc
How do i get the WelshJobApp to be a hyperlink and to open up in another window. I know that it needs a href code, but i cannot figure out where the code needs to sit on the third line?
Response.Write "<tr><td style=""width: 64px;""> </td>"
Response.Write "<td valign=top><b>Welsh Application Form</b></td>"
Response.Write "<td valign=top>" & objRS("WelshJobApp" & "</td></tr>"
I'd appreciate any help with this..thanks
Sze
<font face='Verdana'></font id='Verdana'>
Replies
Replied 01 Apr 2003 05:36:39
01 Apr 2003 05:36:39 Ashok Bhupathy replied:
Hi try this,
<a href= "<% Response.Write "& objRS("WelshJobApp" & " %> target="_blank">"</td></a></tr>
The target will open in a new window and the ahref will create a link. Hope this works. Good luck.
<a href= "<% Response.Write "& objRS("WelshJobApp" & " %> target="_blank">"</td></a></tr>
The target will open in a new window and the ahref will create a link. Hope this works. Good luck.
Replied 01 Apr 2003 14:44:04
01 Apr 2003 14:44:04 Sze-Wai Lai replied:
<font face='Tahoma'>
you were close, i had to make a few changes and got this working.
Response.Write "<td valign=top><a href='" & objRS("WelshJobApp" & "' target='_blank'>" & objRS("WelshJobApp" & "</a></td></tr>"
Thanks for you help.
Sze
</font id='Tahoma'>
you were close, i had to make a few changes and got this working.
Response.Write "<td valign=top><a href='" & objRS("WelshJobApp" & "' target='_blank'>" & objRS("WelshJobApp" & "</a></td></tr>"
Thanks for you help.
Sze
</font id='Tahoma'>
Replied 22 Feb 2005 00:50:57
22 Feb 2005 00:50:57 Simon Howell replied:
I have a similar problem, but I'm trying to put the code inside an If Then statement. This works fine on its own:
<%
Response.Write "<a href='" & rsFrames("Doc" & "' target='_blank'>" & "Link" & "</a>"
%>
but when I add the If Then the link opens a blank window:
<%
If rsFrames.Fields.Item("Doc"="None" Then
Response.Write " "
Else
Response.Write "<a href='" & rsFrames("Doc" & "' target='_blank'>" & "Link" & "</a>"
End If
%>
Any help would be greatly appreciated
Simon
<%
Response.Write "<a href='" & rsFrames("Doc" & "' target='_blank'>" & "Link" & "</a>"
%>
but when I add the If Then the link opens a blank window:
<%
If rsFrames.Fields.Item("Doc"="None" Then
Response.Write " "
Else
Response.Write "<a href='" & rsFrames("Doc" & "' target='_blank'>" & "Link" & "</a>"
End If
%>
Any help would be greatly appreciated
Simon
Replied 22 Feb 2005 14:13:48
22 Feb 2005 14:13:48 Lee Diggins replied:
Hi Simon
Try this:
If rsFrames.Fields.Item("Doc".Value = "None" Then
Response.Write(" "
Else
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ & "" target=""_blank"">" & "Link" & "</a>"
End If
Using this method you will find that the html attributes have a double quote and not single. In asp the single quote is regarded as the start of a comment unless you escape the single quote.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Try this:
If rsFrames.Fields.Item("Doc".Value = "None" Then
Response.Write(" "
Else
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ & "" target=""_blank"">" & "Link" & "</a>"
End If
Using this method you will find that the html attributes have a double quote and not single. In asp the single quote is regarded as the start of a comment unless you escape the single quote.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 22 Feb 2005 17:39:29
22 Feb 2005 17:39:29 Simon Howell replied:
Lee,
Thanks for the reponse - I tried that but I get the same results. You can see the page here:
www.esc-online.com/apps/frames/test_blank.asp
If you click on the links you'll see it opens the new window, but its blank.
It seems to have something to do with the IF THEN statement because if I just have your code without the IF THEN portion it works fine as you can see here:
www.esc-online.com/apps/frames/test.asp
But the purpose of this is to hide the invalid links (only the first three records should show links).
Thanks for the reponse - I tried that but I get the same results. You can see the page here:
www.esc-online.com/apps/frames/test_blank.asp
If you click on the links you'll see it opens the new window, but its blank.
It seems to have something to do with the IF THEN statement because if I just have your code without the IF THEN portion it works fine as you can see here:
www.esc-online.com/apps/frames/test.asp
But the purpose of this is to hide the invalid links (only the first three records should show links).
Replied 22 Feb 2005 18:22:21
22 Feb 2005 18:22:21 Lee Diggins replied:
Hi Simon
My mistake, should of checked before posting, try this:
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ target=""_blank"">Link</a>"
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
My mistake, should of checked before posting, try this:
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ target=""_blank"">Link</a>"
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 22 Feb 2005 18:30:29
22 Feb 2005 18:30:29 Lee Diggins replied:
Hi Simon
The previous post was to fix the link reponse.write string as it was incorrect. Regarding the IF statement, would the recordset actually return the string None or are you checking for NULL?
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
The previous post was to fix the link reponse.write string as it was incorrect. Regarding the IF statement, would the recordset actually return the string None or are you checking for NULL?
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 22 Feb 2005 18:33:15
22 Feb 2005 18:33:15 Simon Howell replied:
Originally I had a blank record and I was saying
If rsFrames.Fields.Item("Doc"=" " Then
Response.Write " "
but this wouldn't work for some reason, so instead I put the word "None" in every record that didn't contain anything. Hence the
If rsFrames.Fields.Item("Doc"="None" Then
Response.Write " "
I tried your last suggestion but I get the same results.
Simon
If rsFrames.Fields.Item("Doc"=" " Then
Response.Write " "
but this wouldn't work for some reason, so instead I put the word "None" in every record that didn't contain anything. Hence the
If rsFrames.Fields.Item("Doc"="None" Then
Response.Write " "
I tried your last suggestion but I get the same results.
Simon
Replied 22 Feb 2005 18:52:57
22 Feb 2005 18:52:57 Lee Diggins replied:
Hi Simon
don't forget the .Value
Also you could have done an If IsNull() check instead of populating all the fields with None. Can you also tell me why some records have links and other do not, is this beacuse of the If statement result?
Post back if you still have a problem and post the entire page code please.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
don't forget the .Value
Also you could have done an If IsNull() check instead of populating all the fields with None. Can you also tell me why some records have links and other do not, is this beacuse of the If statement result?
Post back if you still have a problem and post the entire page code please.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 22 Feb 2005 19:10:47
22 Feb 2005 19:10:47 Simon Howell replied:
Lee,
Being an ASP newbie I don't know where to put that IsNull code. I have replaced the "None" with a blank record again so I would like to know how to.
Seems I have two problems:
1. How to return blank if the record is empty
2. How to write the code to display a hyperlink if there is a value in the record.
Basically, the page is a list of available cobol programs, some of which have pdf documents detailing what they do and some that don't. If there is a pdf file available (the database shows it as a url) then I want it to display a link. If there is no PDF then I don't want it to display anything.
Here's the complete code with my (poor) attempt at using the IsNull thingy (I've indicated the section with the problem with a comment):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/connFrames.asp" -->
<%
Dim rsFrames
Dim rsFrames_numRows
Set rsFrames = Server.CreateObject("ADODB.Recordset"
rsFrames.ActiveConnection = MM_connFrames_STRING
rsFrames.Source = "SELECT * FROM Frames_List, Cat, Version WHERE Frames_List.CatID=Cat.CatID AND Frames_List.VID = Version.VID ORDER BY Frames_List.FrameID"
rsFrames.CursorType = 0
rsFrames.CursorLocation = 2
rsFrames.LockType = 1
rsFrames.Open()
rsFrames_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsFrames_numRows = rsFrames_numRows + Repeat1__numRows
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="frames" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h2>Frame Name </h2></td>
<td><h2>Description</h2></td>
<td><h2>Location</h2></td>
<td><h2>Category</h2></td>
<td><h2>Version</h2></td>
<td><h2>Prg</h2></td>
<td><h2> </h2></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsFrames.EOF))
%>
<tr valign="top">
<td><p><%=(rsFrames.Fields.Item("Name".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("FrameDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("Location".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("CatDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("VDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("Programmer".Value)%></p></td>
<td><p>
<!-- Here's my code I'm having problems with -->
<%
If rsFrames.Fields.Item("Doc".Value = IsNull() Then
Response.Write(" "
Else
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ target=""_blank"">Link</a>"
End If
%>
</p></td>
</tr>
<tr valign="top">
<td></td>
<td>
<%if (rsFrames.Fields.Item("ExtDesc".Value = "None" Then
Response.Write " "
Else
Response.Write("<p><a href=""" & "ext_desc.asp" & "?FrameID=" & rsFrames("FrameID" & """>" & "Extended Description & Installation Notes" & "</a>"
End If
%>
</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="top">
<td colspan="7"><hr></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsFrames.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
rsFrames.Close()
Set rsFrames = Nothing
%>
Being an ASP newbie I don't know where to put that IsNull code. I have replaced the "None" with a blank record again so I would like to know how to.
Seems I have two problems:
1. How to return blank if the record is empty
2. How to write the code to display a hyperlink if there is a value in the record.
Basically, the page is a list of available cobol programs, some of which have pdf documents detailing what they do and some that don't. If there is a pdf file available (the database shows it as a url) then I want it to display a link. If there is no PDF then I don't want it to display anything.
Here's the complete code with my (poor) attempt at using the IsNull thingy (I've indicated the section with the problem with a comment):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/connFrames.asp" -->
<%
Dim rsFrames
Dim rsFrames_numRows
Set rsFrames = Server.CreateObject("ADODB.Recordset"
rsFrames.ActiveConnection = MM_connFrames_STRING
rsFrames.Source = "SELECT * FROM Frames_List, Cat, Version WHERE Frames_List.CatID=Cat.CatID AND Frames_List.VID = Version.VID ORDER BY Frames_List.FrameID"
rsFrames.CursorType = 0
rsFrames.CursorLocation = 2
rsFrames.LockType = 1
rsFrames.Open()
rsFrames_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsFrames_numRows = rsFrames_numRows + Repeat1__numRows
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="frames" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h2>Frame Name </h2></td>
<td><h2>Description</h2></td>
<td><h2>Location</h2></td>
<td><h2>Category</h2></td>
<td><h2>Version</h2></td>
<td><h2>Prg</h2></td>
<td><h2> </h2></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsFrames.EOF))
%>
<tr valign="top">
<td><p><%=(rsFrames.Fields.Item("Name".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("FrameDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("Location".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("CatDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("VDesc".Value)%></p></td>
<td><p><%=(rsFrames.Fields.Item("Programmer".Value)%></p></td>
<td><p>
<!-- Here's my code I'm having problems with -->
<%
If rsFrames.Fields.Item("Doc".Value = IsNull() Then
Response.Write(" "
Else
Response.Write("<a href=""" & rsFrames.Fields.Item("Doc".Value & """ target=""_blank"">Link</a>"
End If
%>
</p></td>
</tr>
<tr valign="top">
<td></td>
<td>
<%if (rsFrames.Fields.Item("ExtDesc".Value = "None" Then
Response.Write " "
Else
Response.Write("<p><a href=""" & "ext_desc.asp" & "?FrameID=" & rsFrames("FrameID" & """>" & "Extended Description & Installation Notes" & "</a>"
End If
%>
</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr valign="top">
<td colspan="7"><hr></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsFrames.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
rsFrames.Close()
Set rsFrames = Nothing
%>
Replied 22 Feb 2005 23:58:12
22 Feb 2005 23:58:12 Lee Diggins replied:
Hi Simon
The IsNull() function would be used like this:
If IsNull(rsFrames.Fields.Item("Doc".Value) Then
Response.Write(""
Else
'your code here
End If
If the value being sent back to the page are not null but are an empty string string then try this:
If rsFrames.Fields.Item("Doc".Value = "" Then
Response.Write(""
Else
'your code here
End If
Do not confuse an empty string and a NULL as they are not the same thing.
Download this MS documentation for scripting technologies, contains vbscript references:
www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Post back if you're still stuck. You can also try doing a test response.write(rsFrames.Fields.Item("Doc".Value) to see where possible the values that are being returned.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
The IsNull() function would be used like this:
If IsNull(rsFrames.Fields.Item("Doc".Value) Then
Response.Write(""
Else
'your code here
End If
If the value being sent back to the page are not null but are an empty string string then try this:
If rsFrames.Fields.Item("Doc".Value = "" Then
Response.Write(""
Else
'your code here
End If
Do not confuse an empty string and a NULL as they are not the same thing.
Download this MS documentation for scripting technologies, contains vbscript references:
www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
Post back if you're still stuck. You can also try doing a test response.write(rsFrames.Fields.Item("Doc".Value) to see where possible the values that are being returned.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>