Solved

ASP code A href not working

Posted on 2014-04-24
19
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 53

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 53

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 53

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 53

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

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!

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 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