How do I use Server.URLEncode on a string?

Posted on 2006-06-02
Last Modified: 2012-06-27
Hi Experts,

I have the following:

document.location.href= "AddLoad.asp?RecDate=" + x.RecDate.value + "&DeliveryNo=" + x.DeliveryNo.value + "&ShipmentNo=" + x.ShipmentNo.value + "&ManualNoteNo=" + x.ManualNoteNo.value + "&ReservationNo=" + x.ReservationNo.value + "&ShipFrom=" + x.ShipFrom.value + "&ShipTo=" + x.ShipTo.value + "&FromProv=" + x.FromProv.options[x.FromProv.selectedIndex].value +"&ToProv=" + x.ToProv.options[x.ToProv.selectedIndex].value + "&PayorFreight=" + x.PayorFreight.options[x.PayorFreight.selectedIndex].value + "&TransUsed=" + x.TransUsed.options[x.TransUsed.selectedIndex].value + "&ContainerInitial=" + x.ContainerInitial.value + "&ContainerID=" + x.ContainerID.value +"&Notes=" + x.Notes.value + "&UpdateDetails=1&EditDetails=1"

x.PayorFreight.options[x.PayorFreight.selectedIndex].value  can contain an ampersand sometimes such as "A&B". How can this be handled?

Question by:indyng
    LVL 15

    Accepted Solution


    LVL 3

    Expert Comment

    Server.URLEncode is a bit thick - as mshogren says use JScript's native escape() and unescape() functions

    Doh! factor avoidance: Make sure you only escape the values, not the URL &'s!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now