escape plus sign (+) in URL, querystring

Results 1 to 7 of 7

Thread: escape plus sign (+) in URL, querystring

  1. #1
    Join Date
    Dec 1969
    Posts
    124

    Default escape plus sign (+) in URL, querystring

    Hi there,<BR><BR>I have a value that I&#039;m passing in the querystring that contains a plus sign (not all the time), does anyone know how to escape the plus sign so that it can get passed to the next page? I tried "escape", but that did not work.<BR><BR>thanks,<BR>MBlast

  2. #2
    Join Date
    Dec 1969
    Posts
    95,958

    Default escape( ) works, but only if you use it right...

    HOW did you try to use escape()? And did you do it with client-side or server-side code?<BR><BR>I could also ask why you are building a querystring "by hand".<BR><BR>So show what you are doing & we&#039;ll see if we can fix it.<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    95,958

    Default DOH on me...

    ...since this is the JS forum, I guess you are using JS.<BR><BR>Okay, so:<BR><BR>&#060;A HREF="#" onClick="location.href=&#039;somepage.asp?foo=&#03 9; + escape(valueWithMaybePlus); return false;"&#062;<BR><BR>but show what you are doing.<BR><BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    124

    Default RE: js code - doesn't work

    openwindow is just a javascript funtion to open a new window...<BR><BR>&#060;A HREF="javascript:openwindow(&#039;test.asp?FieldVa lue=&#039;+escape(document.form1.testfld.value))"& #062;<BR><BR>when retrieving I use......<BR>unescape(Request.QueryString("FieldVa lue")) and was able to retrieve the value, but not the plus sign.<BR><BR>any help is appreciated.<BR><BR>thanks,<BR>MBlast


  5. #5
    Join Date
    Dec 1969
    Posts
    95,958

    Default Request.QueryString( fieldname )

    ...is *ALREADY AND ALWAYS AND AUTOMATICALLY* doing an Unescape for you!<BR><BR>You would *ONLY* use unescape if you were (for some really strange reason) trying to process the raw query string and NOT letting ASP do the work for you.<BR><BR>Get rid of the Unescape and look at what you are getting.<BR><BR>

  6. #6
    Join Date
    Dec 1969
    Posts
    124

    Default RE: Same results

    I&#039;m getting the same result...........the plus sign still does not show up.<BR><BR>MBlast

  7. #7
    Join Date
    Dec 1969
    Posts
    95,958

    Default How irritating!!!

    The JS escape function does *NOT* encode a + sign! <BR><BR>I guess because they presume you will be using JS unescape to decode it.<BR><BR>What a pain.<BR><BR>ASP is smarter. It will unescape *either* a + or %20 to a space. And it will properly encode, as well.<BR><BR>Oh, well. Try this: <BR><BR>************<BR>&#060;HTML&#062;&#060;BODY &#062;<BR><BR>&#060;%<BR>For Each fld In Request.QueryString<BR> Response.Write fld & ": " & Request.QueryString(fld) & "&#060;P&#062;"<BR>Next<BR>%&#062;<BR>&#060;HR&#06 2;<BR><BR>&#060;A HREF="#" onClick="go();"&#062; demo for mblast &#060;/A&#062;<BR><BR>&#060;FORM&#062;<BR>&#060;INPUT Name="demo" Value="stuff with spaces"&#062;<BR>&#060;INPUT Name="also" Value="!@#$%^&*()_+"&#062;<BR>&#060;INPUT Type=Submit&#062;<BR>&#060;/FORM&#062;<BR><BR>&#060;SCRIPT&#062;<BR>function fixEscape(str)<BR>{<BR> return escape(str).replace( /+/g, "%2B" );<BR>}<BR>function go( )<BR>{<BR> var url = "mblast.asp?demo=" + fixEscape(document.forms[0].demo.value) <BR> + "&also=" + fixEscape(document.forms[0].also.value);<BR> location.href = url;<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies