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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink problem with space 1

Status
Not open for further replies.

Brian10

Programmer
Jul 24, 2001
3
ZA
I have written some code that uses a Button to redirect the user to another asp page. This button uses a hyperlink to direct the user. But I also pass variables in this string to the new ASP page, and in doing this I have a problem.

When a name is separated by a space as in
FirstName LastName you need to encapsulate the name with 'i.e. 'FirstName LastName'. But as soon as you do this the hyperlink no longer functions as it sees the first ' as the end of the string. Is there a solution to this problem?

The code for the Button is bellow

This works
<%'HString= &quot;'./customer.asp?ID=1&Cust_Name=FirstName LastName&quot;%>
<p align=&quot;center&quot;><input type=button value=&quot;Change&quot; onClick=&quot;location.href= <%=HString%>&quot;></p>

This does not.

<%'HString= &quot;'./customer.asp?ID=1&Cust_Name='FirstName LastName'&quot;%>
<p align=&quot;center&quot;><input type=button value=&quot;Change&quot; onClick=&quot;location.href= <%=HString%>&quot;></p>


 
What about:

<%
HString= &quot;./customer.asp?ID=1&Cust_Name='FirstName LastName'&quot;
%>

Why were the two single quotes there??
Mise Le Meas,

Mighty :)
 
You have to URLEncode your strings.

This mean that the space caracter will be replaced by %20 (20 in hexa is 32->Chr(32)). I think the server ussually knows how to decode them.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
I have decided to answer my own question as I have found the solution.
Instead of using ‘use %27.

%27 =’ in html
 
Brain, try using the URLEncode method.
(i.e. Hstring = URLEncode(/customer.asp?ID=1&Cust_Name=FirstName LastName)

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top