Solved

ASP code A href not working

Posted on 2014-04-24
19
421 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

690 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