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

Problems with querystring with # or + 1

Status
Not open for further replies.

aspnetvbnetnerd

Programmer
Feb 3, 2008
31
SE
I have a problem sending querystring in javascript using # or +

I asp when using # or + sign the you use Server.UrlEncode
Code:
ace.asp?competence=<% =Server.UrlEncode("C#+sql server 2005+C++")%>
and when I want to retrieve the querystring competence it will show "C#+sql server 2005+C++"

If I want to send querystring with Javascript competens and the value "C#+sql server 2005+C++". It will just show "C" when retrieve the querystring competens.

Is there any similar in javascript using Server.UrlEncode
 
Use the following:
Code:
escape("/C# and C++ info.html");
This will yield:
Code:
/C%23%20and%20C++%20info.html
Effectively converting space characters to %20 and # characters to %23. The + character doesn't need converting.

You can convert such a string back using:
Code:
unescape("/C%23%20and%20C++%20info.html");
Browsers will auto-magically do this conversion for you.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
This is how it's done in the window.open().
[tt] window.open('ace.asp?competence='+encodeURIComponent('C#+sql server 2005+C++'))
[/tt]
 
Indeed, escape is not ideal for URIs... I should pay more attention to the question :)

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
It seems that it works with both using encodeURIComponent and escape

Thank you very much.
 
In most cases, it is fine for escape,... not on this one with "+". I hope you've tested it and drawn proper conclusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top