Solved

ASP code A href not working

Posted on 2014-04-24
19
417 Views
Last Modified: 2014-04-25
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
Comment
Question by:Thomas Grassi
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021647
for each song in arraySongs
   response.write "<a href="""&song&"">"&song&"</a>"
 next

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021651
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
 
LVL 58

Expert Comment

by:Gary
ID: 40021654
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021659
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
 
LVL 58

Expert Comment

by:Gary
ID: 40021664
response.write "<a href=""" & song & """>" & song & "</a><br>"

Check out what site???
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021667
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021669
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
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021672
Scott

check it out now 404 errors file or path not found

see above
0
 
LVL 58

Expert Comment

by:Gary
ID: 40021675
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
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021682
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
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40021691
response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>"
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40021692
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
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021695
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
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021697
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
 
LVL 58

Expert Comment

by:Gary
ID: 40021702
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
 
LVL 33

Expert Comment

by:Big Monty
ID: 40021706
Sorry it should be
response.write "<li><a href=""/mp3/""" & Replace( Replace( song, "\", "/" ), "M:\", "" ) &">"&song&"</a></li>"
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 40021707
Also Thanks to Scott and Big Monty for responding

Will be posting another question for you guys in a little while
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021708
I thought you said you had a routine to transform the url?
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021721
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question