ASP generated hyperlink w/ access 2003 data item with/without spac

G

Guest

when creating an .asp page in DreamWeaver MX, a hyperlink created from
information stored in an access 2003 database, the hyperlink does not create
properly.

here is the relevant code from the web page:

<body>

<%
Dim oConn
Dim oRs
Dim filePath

' Map authors database to physical path

filePath = Server.MapPath("../access_db/music.mdb")

' Create ADO Connection Component to connect with sample database

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath

Set oRs = oConn.Execute ("select * from SONG_TITLES where WRITTEN = True
and RECORDED = True and MASTERED = True")

Dim title
Dim length
Dim complete
Dim projectID
Dim link

Dim credits

%>
<font face="book antiqua">

<table>
<tr>
<td>


</td>
</tr>
</table>

<table align="center" width="100%" height="100%" border=1>

<tr>
<th width="20%">
TITLE
</th>


<%
do while not oRs.EOF

title = oRs("TITLE")

length = oRs("LENGTH")
complete = oRs("DATE")
projectID = oRs("PRIMARY_PROJECT_ID")

link = "<a href = http://www.gemoll.net/davidgemoll.net/asx/" & title &
".asx target=new>"
Response.Write(link)

Response.Write("<tr align = center width=" & "100%" &"><td width=" & "20%"
& ">" & link & title & "</a></td></tr>")

oRs.movenext

loop
%>

</table>

</font>


</body>

************************

problem:

when the variable 'title' is populated with a data item with NO spaces, the
link works fine.

when the variable 'title' is populated with a data item with spaces, the
link fails. the address bar shows the link properly up to the first space in
the data item used to create the link.

now, i originally thought the the response.write function interpreted the
spaces in the variable differently when written as part of an anchor tag;
upon further testing...i became convinced this was a bug.

i replaced the variable with a hard coded value with spaces and the behavior
did not change.

i tried referencing the recordset directly, by-passing the variable all
together...this did not work either.

just before giving up, it dawned on me to 'check the source code after the
..asp page is created'.

so, with the page displayed, i clicked view, source code and reviewed the
..asp source code in notepad.

to my surprise, the .asp source code was correct...in other words the
hyperlinks correct, with or without spaces in the source code...however, the
hyperlinks with spaces, do not translate to the address bar of the
'target=new' browser.

i have kept a copy of the file in question with the above described behavior
here:

http://www.gemoll.net/davidgemoll.net/microsoft.asp

the above page was created with the above code, minus the irrelevant code;
if you view the source code, all of the hyperlinks show correct. however, the
song titles with spaces in them do not work, while the single word song title
links work properly.

one last thing...the same variable is used to display the song title as is
used to create the hyperlink...notice the song titles all display properly.

if this is not a bug, i haven't the slightest clue as to why it would behave
differently with or without space...
 
R

Rob ^_^

Hi Dave,

Enclose your href attribute within quotes.

So, href=http://www.gemoll.net/davidgemoll.net/asx/PREY TO THE EVIL.asx

becomes

href="http://www.gemoll.net/davidgemoll.net/asx/PREY TO THE EVIL.asx"


or in your source

link = "<a href = http://www.gemoll.net/davidgemoll.net/asx/" & title &
".asx target=new>"

becomes

link = "<a href = ""http://www.gemoll.net/davidgemoll.net/asx/" & title &
".asx"" target=""new"">"
or
Just insert the Title variable within the <a></a> tag

<a href="http://www.gemoll.net/davidgemoll.net/asx/<%=title%>.asx"
target="new">


Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top