Solved

ASP code A href not working

Posted on 2014-04-24
19
410 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 32

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 32

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now