Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic HREF / data type problem 1

Status
Not open for further replies.

Krickles

Technical User
Apr 13, 2002
92
US
I am trying to dynamically create href links based on database values. The problem occurs with only one field.

Details:[ul][li]MS SQL Server 2000[/li]
[li]Data type: varchar(50) [/li]
[li]Field name: plant[/li]
[li]Generic data sample: XX[single blank space]PlantName[/li]
[li]Examples of data: [/li]
[ol][li]30 East Birmingham[/li]
[li]40 Downtown[/li][/ol][li]Recordset: rs30P_Y[/li][/ul]
Sample code attempts:[ol][li]
Code:
Response.Write (“<A href=”)
Response.Write “2003”&Cstr(rs30P_Y(“plant”)&”detail.asp”
Response.Write (“></A>”)
[/li]

[li]
Code:
Response.Write (“<A href=detail?year=”)year(date())&”&plant=”
Response.Write &rs30P_Y(“plant”)&”.asp”
Response.Write (“></A>”)
[/li][/ol]

In both code examples above the returned value of rs30P_Y cuts off before the blank space and will not print anything I include after the blank space. Result example:
[tt]
[/tt]
However, if I try
Code:
Response.Write rs30P_Y(“plant”)
, the result is as expected. Example:
Code:
Response.Write rs30P_Y(“plant”)
Returns
Code:
30 East Birmingham

What I want is to dynamically generate [YEAR][PLANTNAME]detail.asp as the link and include values to submit to a stored procedure. So, if someone clicked on plant listing 30 East Birmingham, the link will look similar to:
[tt]
[/tt]
and I could then set variables to pass to the stored procedure to return a result set.

If I am trying something goofy please suggest another method. I don’t expect someone to do the work, just provide some guidance.

Kind Regards,

Krickles
 
It's because the href property of your anchor tag doesn't have quotes around it -- the browser assumes everything after the space is some other property.

You can fix it one of two ways:
Code:
Response.Write(&quot;<A href=&quot;&quot;detail.asp?year=&quot; & year(date())& &quot;&plant=&quot;
Response.Write(rs30P_Y(&quot;plant&quot;) & &quot;&quot;&quot;>Something Here</a>&quot;)
because two double-quotes in a row writes out a double-quote.

Alternately you can have ASP encode all of the spaces to fix it:
Code:
Response.Write(&quot;<A href=detail.asp?year=&quot; & year(date())& &quot;&plant=&quot;
Response.Write(Server.URLEncode(rs30P_Y(&quot;plant&quot;)) & &quot;>Something Here</a>&quot;)
(Note that I also moved your .asp extensions because they were in the wrong place and added link text.)
 
Thanks so much. You solved my problem! Kind Regards, Krickles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top