Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

ASP code A href not working

IIS 6
ASP classic
SQL 2008

My Site has a search button which works and presents a list from my sql database.
From the list you can check the check box to select the items you wish and click the submit button.

The next page page2.asp presents a list of only the items checked.

I need this list to be outputted as a url so them can click on the item to open it.

My code is as follows

<%
if request.form<>"" then

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
for each song in arraySongs
   response.write song&"<br>"
   next
else
response.write "You did not post any data yet<br>"
end if
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window


this line response.write song&"<br>" I tried this

response.write <a href= song& </a>"<br>"

Get http 500 error

I know it is this line of code because it is the only line I change.

I just can not figure out this code.

The example output is this
M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\09-Eliminator-Dirty Dog.mp3

In order to make this work also need to convert the "\" to "/"

Any help will be great

Thanks in advance
0
Thomas Grassi
Asked:
Thomas Grassi
  • 8
  • 5
  • 4
  • +1
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
for each song in arraySongs
   response.write "<a href="""&song&"">"&song&"</a>"
 next

Open in new window

0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Scott,

Scott,

Got the url but it is all on one line how do I break <br> the line between each entry

output looks like this
M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\09-Eliminator-Dirty Dog.mp3 M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\10-Eliminator-If I Could Only Flag Her Down.mp3 M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\11-Eliminator-Bad Girl.mp3 M:\Music\MP3MusicAlbums\ZZ Top\Greatest Hits\01-Greatest Hits-Gimme All Your Lovin'.mp3

check the site out
0
 
GaryCommented:
The format would be like this
response.write "<a href=""" & song &"""> & song & "</a><br>"

But
M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\09-Eliminator-Dirty Dog.mp3

is not a valid path, it needs to be a path on the server - forget replacing \ with / it doesn't matter
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Thomas GrassiSystems AdministratorAuthor Commented:
response.write "<a href=""" & song &"""> & song & "</a><br>"


HTTP 500

check out the site

For the path ok lets get the url working first and then will see

Thanks
0
 
GaryCommented:
response.write "<a href=""" & song & """>" & song & "</a><br>"

Check out what site???
0
 
Scott Fell, EE MVEDeveloperCommented:
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Gary

<%
if request.form<>"" then

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""&song&"">"&song&"</a></li>"
next
response.write "</ul>" 
else
response.write "You did not post any data yet<br>"
end if
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window


this is now producing the a url

www.tomsmp3.com

but when you click on the url it gives you 404 error which means path or file not found

Believe we need to convert the "\" to "/" for the url to work
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Scott

check it out now 404 errors file or path not found

see above
0
 
GaryCommented:
See above

But
M:\Music\MP3MusicAlbums\ZZ Top\Eliminator\09-Eliminator-Dirty Dog.mp3

is not a valid path, it needs to be a path on the server


e.g.
/MP3MusicAlbums\ZZ Top\Eliminator\09-Eliminator-Dirty Dog.mp3

(spaces in a url are a bad thing)
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Guys

when you hoover over the url  you get this hyper link

http://www.tomsmp3.com/&song&

this is what we should get

http://www.tomsmp3.com/mp3/mp3musicalbums/10CC/Billboard%20Top%20100%20-%201975/01-Billboard%20Top%20100%20-%201975-42%20I'm%20Not%20In%20Love.mp3

question is how I typed this in and it works
0
 
GaryCommented:
response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>"
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
a bit of a hack, but to get the right url format, you could do:

<%
if request.form<>"" then

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs, 
   response.write "<li><a href="/mp3/"& Replace( Replace( song, "\", "/" ), "M:\", "" ) &"">"&song&"</a></li>"
next
response.write "</ul>" 
else
response.write "You did not post any data yet<br>"
end if
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window

0
 
Scott Fell, EE MVEDeveloperCommented:
Gary gave you the correct code.    Should be 3 quotes.

for each song in arraySongs
   response.write "<a href="""&song&""">"&song&"</a>"
 next

Open in new window

0
 
Thomas GrassiSystems AdministratorAuthor Commented:
big Monty

Thanks

Microsoft VBScript compilation  error '800a0401'

Expected end of statement

/page2.asp, line 8
response.write "<li><a href="/mp3/"& Replace( Replace( song, "\", "/" ), "M:\", "" ) &"">"&song&"</a></li>"
------------------------------------------------------------------------------------------------------^
0
 
GaryCommented:
Try this, the whole caboodle

<%
if request.form<>"" then

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & replace(song,"M:\Music\MP3MusicAlbums\","") & "</a></li>"
   next
else
response.write "You did not post any data yet<br>"
end if
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window

0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Sorry it should be
response.write "<li><a href=""/mp3/""" & Replace( Replace( song, "\", "/" ), "M:\", "" ) &">"&song&"</a></li>"
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Also Thanks to Scott and Big Monty for responding

Will be posting another question for you guys in a little while
0
 
Scott Fell, EE MVEDeveloperCommented:
I thought you said you had a routine to transform the url?
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Scott

This is what I used in my main page for reading thru on the files on the file system drive.

This works also.

Response.Write("<ul>")
    for each item in folder.Files
       If UCase(fs.GetExtensionName(item.name)) = "MP3" or UCase(fs.GetExtensionName(item.name)) = "M4A" or UCase(fs.GetExtensionName(item.name)) = "M4B" or UCase(fs.GetExtensionName(item.name)) = "M4P" or UCase(fs.GetExtensionName(item.name)) = "MP4" or UCase(fs.GetExtensionName(item.name)) = "WMA" Then
          url = MapURL(item.path)
          Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
       end if
    next
        Response.Write("</ul>")
   end sub
   function MapURL(path)
     dim rootPath, url
     'Convert a physical file path to a URL for hypertext links.
     url = "/mp3/" & Right(path, Len(path) - 9)
     MapURL = Replace(url, "\", "/")

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now