Click to See Complete Forum and Search --> : removing characters in string
webgeek
04-16-2003, 01:23 PM
I have a form for users to fill out. When they press SUBMIT it takes them to a contract page that takes the values submitted and uses them to pre-fill out the contract page. The problem is, along with the form values, "+" characters are inserted where blank spaces should be. For example:
5200 west century blvd, suite 800
would look like:
5200+west+century+blvd,+suite+800
How do I get rid of these plus characters and replace them with a blank space?
khalidali63
04-16-2003, 01:26 PM
Please read about escape and unescape function in javascript.
may be a google search will return enough results
Cheers
Khalid
webgeek
04-16-2003, 01:47 PM
Not much help, as + is one of those un encoded characters. I saw how to turn %20 back into a blank space, and read this:
http://www.htmlgoodies.com/beyond/jspass.html
Try typing two words into one of the input fields of the example, you will see what I am encountering.
That article mentions my problem exactly, but only states that I will have to "write some extra code" in order to get rid of the plus marks in my output. I want that code, as I don't know how to write it.
Nedals
04-16-2003, 01:50 PM
Is this done using a server-side script or are you passing variables via the URL?
khalidali63's unescape will remove the '+'s but only if you are populating the contract page using javascript.
webgeek
04-16-2003, 01:57 PM
Maybe this will help.
URL
http://www.phoenixsoftware.com/Evaluation.htm
DrDaMour
04-16-2003, 02:03 PM
nobody really needs any help with this, the idead is that a string is an array of characters. so you need to search the string to find the index of the + character, then replace that with a space.
Since you are using a form, i would have to assume you're using something other than javascript, unless you are hacking it by using the get URL function in javascript. If that is the case, you need to look for functions on javascript strings, google it. I don't think anyone wants to just write yoru code for you
Nedals
04-16-2003, 02:05 PM
When sending data over the net, a few chars must be encoded. So, in your case use escape prior to sending and unescape on reciept.
address = escape(5200 west century blvd, suite 800);
Which adds the '+'
and
address = unescape(value (from name/value pair))
webgeek
04-16-2003, 02:08 PM
I didn't ask anyone to write the code for me. Time is not a luxury I have right now. I was hoping someone could giev me a more direct answer or example.
Moderator's note: I know I sometimes fly off the handle myself, but lets all try to be a little kinder. Thanks.
Nedals
04-16-2003, 05:49 PM
Dave..
You're right, of course. I was indeed getting confused with the GET method. However, for this application, since webgeek is passing data via the URL, it seemed that using the escape() and unescape() methods would be more appropiate.
Your comments would be appreciated. :)
webgeek
04-17-2003, 12:45 PM
Thanks, Dave
Your answer was right on!