Link to home
Start Free TrialLog in
Avatar of Evert Jor
Evert JorFlag for Norway

asked on

Need help with hyperlink syntax in ASP

I'm trying to insert a hyperlink in the following line, but I can't get the syntax right. I need a hyperlink to open in a new page inserted where the text "Hyperlink" is below:

if showproductid=TRUE then print "<div class=""detailid""><strong>" & xxPrId & ":</strong> <span itemprop=""productID"">" & rs("pID") & "Hyperlink"&"</span></div>"

Avatar of HainKurt
HainKurt
Flag of Canada image

try this. use ' inside to make easy to follow

if showproductid then print "<div class='detailid'><strong>" & xxPrId & ":</strong><span itemprop='productID'>" & rs("pID") & "Hyperlink</span></div>"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you want a link to open a new page
if showproductid then print "<div class='detailid'><strong>" & xxPrId & ":</strong><span itemprop='productID'><a href='??page url here??' target='_blank'>" & rs("pID") & "</a></span></div>"

Open in new window

First, look at what the output should be for the HTML.  https://www.w3schools.com/tags/att_a_target.asp  The example there is
<a href="https://www.w3schools.com" target="_blank">Visit W3Schools</a> 

Open in new window


So your example should be something like below. I may have some of the rendered HTML wrong, I was just guessing based on the code you provided.

<div class="detailid"><strong> SOME_TEXT </strong> <span itemprop="productID">123   <a href="https://www.w3schools.com" target="_blank">Visit W3Schools</a> </span></div>

Open in new window


HainKurt said right away to use single quotes instead of double quotes because it makes it easier. In other words, instead, of below
response.write  "<a href=""https://www.w3schools.com"" target=""_blank"">Visit W3Schools</a>"

Open in new window

it is much easier to use
response.write "<a href='https://www.w3schools.com' target='_blank'>Visit W3Schools</a>"

Open in new window


You will find the result is the same when you render the page.

Putting it all together.

showproductid = "TRUE"
detailid = 123
xxPrId  ="abc"
productID ="xyz"
' rs("pID") recordset assume 789
' ASSUME HYPERLINK IS ON rs("pID")  


if showproductid = "TRUE" then
      response.write "<div class='" & detailid & "'><strong>'" & xxPrId & "</strong> <span itemprop='"&productID&"'><a href='"& rs("pID") & "' target='_blank'>" & rs("pidD") & "</a> </span></div>" 
end if

Open in new window


  That should work out to

<div class="123><strong>abc</strong> <span itemprop="xyz"><a href="789">789</a> </span></div>

Open in new window

I have not tested, and may have a typo, but give it a try