Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unescape Not Working

    Hi,

    I've put up a form on my website that is supposed to pass the entered values from one page to a new page that opens and show the data exactly as typed on the new page. I'm using a javascript that I got from another javascript site that i have modified to fit my needs. For some reason, any spaces that are input into the form are still being displayed on the next page as "+" signs. For example, if I input "New York," it will show up on the new page as "New+York." How do I fix this problem? There is already coding in place that uses the unescape function, but it still won't display properly. Could someone please have a look at my webpage to see if they can figure out the problem? It's at melaniestype.com/serviceagreement.html. The output form is at melaniestype.com/serviceagreementoutput.html. I'd appreciate a quick response. Thanks.

  • #2
    New Coder
    Join Date
    Feb 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HERE'S PART OF THE CODE

    <!-- Begin
    function getParams() {
    var idx = document.URL.indexOf('?');
    var params = new Array();
    if (idx != -1) {
    var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
    for (var i=0; i<pairs.length; i++) {
    nameVal = pairs[i].split('=');
    params[nameVal[0]] = nameVal[1];
    }
    }
    return params;
    }
    params = getParams();
    // End -->
    </script>
    </HEAD>

    <!-- STEP THREE: Put this on the page that should read the values -->

    <BODY link=forestgreen vlink=forestgreen><nobanner>



    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    requiredclientname = unescape(params["requiredclientname"]);
    requiredclientID = unescape(params["requiredclientID"]);



    When I say

    document.write("Client name is " + requiredclientname + ".");

    for example, it prints wrong.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a quick fix:

    Code:
    requiredclientname = unescape(params["requiredclientname"]).replace(/\+/g, " ");
    .....Willy

  • #4
    New Coder
    Join Date
    Feb 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, thank you so much! Finally works.


    But how does that code actually work? What's with the front and back slashes? Sorry if I sound like, duh, cause I'm new to this whole thing.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You should unescape the name also:

    params[unescape(nameVal[0].replace(/\+/g, " "))]=unescape(nameVal[1].replace(/\+/g, " "));

    See this thread for the issues in parsing querystrings.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's a regular expression and since I am still struggling with them,
    I am not qualified to offer a substantive explanation. But, I'll try.

    The forward slashes / are the wrapper.
    The backslash \ escapes the reserved +
    And the g indicates it is to be global. (replace all instances of)

    Liorean has a good tutorial on regular expressions
    but I do not have the link handy.

    Furthermore, Glenns solution is much better
    Not only will the pairs name be covered, you won't
    need to add the .replace(...) to all of your values.

    .....Willy

  • #7
    New Coder
    Join Date
    Feb 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot, you guys. I had already used your idea, Willy, before Glenn had a chance to post, and I don't really understand how your code works, Glenn. I follow it kind of, but I don't understand the namVal or the brackets with [0] and [1] following namVal. Would "namVal" go in place of the names I have, i.e. "requiredclientname"...? Could you explain that code to me, Glenn, in basic terms?

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Maybe this is clearer...

    var name, value, nameVal;
    for (var i=0; i<pairs.length; i++) {
    nameVal = pairs[i].split('='); //returns an array with 2 items
    name = unescape(nameVal[0].replace(/\+/g, " ")); //unescape item 1 from the array and replace +'s with spaces
    value = unescape(nameVal[1].replace(/\+/g, " ")); //unescape item 2 from the array and replace +'s with spaces
    params[name] = value; //put the name-value in "hash array"
    }

    and then you access the names like these:

    var requiredclientname = params["requiredclientname"];
    var requiredclientID = params["requiredclientID"];

    Read the links I posted for more comprehensive discussion on this topic.
    Last edited by glenngv; 02-02-2004 at 04:42 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New Coder
    Join Date
    Feb 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks, Glenn

    That IS a lot clearer. Boy, this site is a very big help. I had been trying my best to fix the problem myself to no avail. I'm glad you guys were there to help. Thanks again. Take care


  •  

    Posting Permissions

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