Creating a URL encoded value in JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Howe

    #1

    Creating a URL encoded value in JavaScript

    I'm working on a web application which needs to submit information to the
    server via a URL string. The URL can contain values retrieved from form
    input fields. I'm using the escape function to preprocess values from
    input fields, but I have a problem when the input field contains a '+'
    (plus sign). Since the escaped value gets put into a URL, the server
    doesn't see the '+', but rather a blank. Is there any other javascript
    function which will automatically escape a '+' in addition to the other
    characters that it already escapes?

    Thanks.

    --
    James Howe
  • Michael Winter

    #2
    Re: Creating a URL encoded value in JavaScript

    On 06 Apr 2004 16:31:06 EDT, James Howe
    <concentricnews @wingspread.ima p-mail.com> wrote:
    [color=blue]
    > I'm working on a web application which needs to submit information to
    > the server via a URL string. The URL can contain values retrieved from
    > form input fields. I'm using the escape function to preprocess values
    > from input fields, but I have a problem when the input field contains a
    > '+' (plus sign). Since the escaped value gets put into a URL, the
    > server doesn't see the '+', but rather a blank. Is there any other
    > javascript function which will automatically escape a '+' in addition
    > to the other characters that it already escapes?[/color]

    The simplest thing to do is convert plus symbols to their hex-escaped
    versions first, then use the escape() function. When you perform the
    reverse, convert plus symbols to spaces, then use unescape().

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    Working...