How to return a link for given text using asp code - asp-classic

I am trying to return a link for the given text.
Here is the code:
<%
dim t
t = Request.QueryString("txt")
Response.Write("<a href = \" page2.html \" >" & t & "<\a>")
%>
Can anybody tell me what's wrong with the code?, it is not working.

To escape the " in vbscript, you have to double it. That is use "" for printing ".
Response.Write("<a href = "" page2.html "" >" & t & "<\a>")

Related

Creating a hyperlink in the VB can't seem the quotes right

Creating a hyperlink in the VB which goes to a panel in the aspx page.
code I have so far is:
eventlist.Text = eventlist.Text & "<div class='event-side-label'>"
eventlist.Text = eventlist.Text & "" & Site link & ""
eventlist.Text = eventlist.Text & "</div>"
I can't seem to get the single and double quotes right, keep getting an error saying end of statement expected just at the quotes after row("event_url").
URL worked fine until I tried to put the target'_blank' in.
Can anyone help out here?
You are missing an & after "& row("event_url") "

Podcast rss feed reading itunes image in classic asp

I'm working on a rss feed reader and seems so work great.
The only thing that I seem not to get working is to read the image in the feed.
<itunes:image href="http://www.itunes.com/image.jpg"/>
Can anyone help?
This is a part of my code.
For Each objItem in objItems
On Error Resume Next
TheTitle = objItem.selectSingleNode("title").Text
TheLink = objItem.selectSingleNode("image").Text
Theimg = objItem.SelectSingleNode("itunes").Attributes(":image").InnerText
Response.Write "<div class='article'>" &_
"<a href=" & TheLink & ">" & _
"<span>" & Theimg & TheTitle & "</span>" & _
"</a>" & _
"</div>"
Next
Your image address needs to go inside an image tag
Response.Write "<div class=""article"">" &_
"<a href=""" & TheLink & """>" & _
"<img src=""" & Theimg & """ alt=""" & TheTitle & """ />" & _
"</a>" & _
"</div>"
If you're wondering why all the double quotes, see this question
Adding quotes to a string in VBScript
As an aside, if you understand XSL then I find that the best way to handle RSS feeds in Classic ASP is to do a server side XSLT transformation. The ASP looks like this
set xml = Server.CreateObject("Msxml2.DomDocument.6.0")
xml.setProperty "ServerHTTPRequest", true
xml.async = false
xml.validateOnParse = false
xml.load("http://your-rss-feed")
set xsl = Server.CreateObject("Msxml2.DomDocument.6.0")
xsl.load(Server.Mappath("yourxslfile.xsl"))
Response.Write(xml.transformNode(xsl))
set xsl = nothing
set xml = nothing

Formatting classic ASP in an email

Can anyone tell me how i would format the following ASP line for an email with bold
email_body = email_body & "Full Name: " & fullname & vbcrlf & vbcrlf
I also tried:
email_body = email_body & "<b>Full Name:</b> " & fullname & vbcrlf & vbcrlf
But it didn't work, just showed the tags
The email just showed the bold tags
Sorry the format I want is
Full Name: John Smith
And the ASP code is:
email_body = email_body & "Full Name: " & fullname & vbcrlf & vbcrlf <br />
I tried adding the Bold tags around the Full name, but it didn't format it just showed the actual tags
In order to have bold or other text formatting in an email, you have to make sure that the email is sent as HTML and not plain text. In your case it seems to be sent as plain text. Here are the ways to do it with the common mail components (some code copied from respective documentations):
CDO
objMessage.HTMLBody = "<h1>This is some sample message html.</h1>"
(the property is HTMLBody, not simply Body). Source: http://www.paulsadowski.com/wsh/cdo.htm
ASPEmail
Add:
Mail.IsHTML = True
Source: http://www.aspemail.com/manual_02.html
JMail
Add:
JMail.ContentType = "text/html"
Source: http://www.aspwebpro.com/aspscripts/email/jmail.asp
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.from = "me#me.com"
Mail.to = "me#me.com"
Mail.subject = "To Me"
sBody = "<h1>blah blah</h1>"
Mail.bodyFormat = CdoBodyFormatHTML
Mail.body = sBody
Mail.send

concatenating string in classic asp

I am trying to concatenate image url (string) with img tag but i am not sure how to put " after src=. Please help to concatenate this.
response.write("<img src=" & '"' & rs("ProductImage") & '"' &" /><br/>")
You have to double up the quotes:
Response.Write("<img src=""" & rs("ProductImage") & """ /><br/>")
Since HTML can use double quotes or single quotes, why not just use single quotes for the HTML. So your code would look like this:
response.write("<img src='" & rs("ProductImage") & "' /><br/>")
The resulting output would look like this:
<img src='ProductImageUrl' /><br/>
Another option is to use the chr function:
Response.Write("<img src=" & chr(34) & rs("ProductImage") & chr(34) & " /><br/>")
ascii code 34 is the double quote. We use this all the time when writing out HTML.

ASP - Printing the entire request contents

I'm debugging some ASP code and I need to get a quick printout of the current Request datastructure, which I believe is an array of key/value pairs.
I see that Request.Form("key") is the method for extracting individual elements.
Any tips on printing out the entire thing?
Try this
For Each item In Request.Form
Response.Write "Key: " & item & " - Value: " & Request.Form(item) & "<BR />"
Next
Working:
For x = 1 to Request.Form.Count
Response.Write x & ": " _
& Request.Form.Key(x) & "=" & Request.Form.Item(x) & "<BR>"
Next
I have other Classic ASP code snippets here:
https://github.com/RaviRamDhali/programming-procedure/tree/master/Snippets/ASP
Try a FOR/EACH loop:
for each x in Request.Form
Response.Write(x)
Next

Resources