Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I "escape" a set of fields? I'm a stumped newbie! 1

Status
Not open for further replies.

JCHallgren

Technical User
Dec 17, 2004
47
US
Ok...I'm VERY new to this...have read as much as i can find online...but I don't get it...here is what i have:

CD = "CRuserName:" + escape (document.CRaddForm.CRuserName.value ) + "|"
+ "CRuserEmail:" + escape(document.CRaddForm.CRuserEmail.value);

I need to have the form values escaped but not the entire result string...
I have tried numerous attempts, but it eludes me...help??
 
JCH-

Its abit hard to tell you what the problem might be without taking a peek at the rest of the code, and especially the output...what "CD" actually equals after that statement.

Try posting abit more information here and help will come easier. I often find that on my way to making a complete post I find the solution to my problem.

In the mean time, here are some debugging tips for you. These are very very helpful if used wisely.

Simplify each statement as much as possible so that you can isolate the problem to one specific area of the statement. In this case, I would start by taking out the escape() method calls and checking the output of the form input boxes.

Space in periodic alert boxes so that you can keep up with your variables. If you have done any other programming and debugging this is kind of like the watch function of most debuggers. Some hints and tips for the alert debugging method:
[ol][li]"\n" makes a newline. ex: "the cat\njumped over the moon"
would print:
the cat
jumped over the moon[/li]
[li]"\t" makes a tab character. very usefull for formatting and structuring the variables you are alerting yourlself to.[/li][/ol]

Keep these simple debugging techniques in mind, they are helpfull.

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

robert (at) robertcarpenter (dot) net
 
Using the alerts was how I determined that the "escape" was NOT being processed. The original value of those fields was in the result string CD, not a modified vers of it.

I only gave the line involved as I believe that I am not using the escape function correctly and needed aid on syntax. Does the "xxxx.value" field need to be processed by another function first before using the escape?

What I desire is an output similar to "CRuserName:J%20Hall|CRuserEmail:j%20hall%22xxx%23net" (where I know %22/23 are not correct but represent @ and period for this example)
 
You can use encodeURIComponent() instead. It won't change periods, but periods don't need to be changed.

Code:
var un = encodeURIComponent( document.CRaddForm.CRuserName.value );
var em = encodeURIComponent( document.CRaddForm.CRuserEmail.value );
var cd = "CRuserName:" + un + "|CRuserEmail:" + em;

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
cLFlaVA, is it required that each field be URIC'd before the string is combined? Or can the URIC be used within it as in the syntax I used with escape?

(I am attempting to build a consolidated cookie to make some other processing easier)

And THANKS for the input!
 
That issue had me going for over two hours last nite!
I figured I was using wrong function but all the examples i found used escape on a simple variable...not on a ".value"

And neatness is in the eye of the coder! (Embedded is neater to me)

Now I can maybe get cookie out...may have some "issues" getting it back in...but let me work on it for a while first..
 
PS: I did some searching on the URIC and see that it may not be available to older browsers...is this a legit concern as my users tend to be behind the times?
 
If you run into problems with your users, you may have to revert to using escape() along with the replace() function to "manually" change @ symbols to their respective encoded values.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
DUH! Seems I found the answer! It was NOT my code...
At I was able to try out the various options...

What I did NOT know (even after looking around web) was that certain special chars are left intact!

The @_+=./* are those....had I known that last nite, i would have gotten two more hours of sleep and 3 hrs more work this morning!

So when i saw my email addr as is, I believed it didn't work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top