Click to See Complete Forum and Search --> : Passing special characters in query string
n8guy
11-17-2003, 06:02 PM
I have a problem with passing apostrophes and quotation marks in my JavaScript code. This is particularly frustrating, as I have tried many different things to no avail. I have tried it with the escape character (\'), without the escape character ('), and a couple other things.
This is the code in question:
<a href="#" onclick="window.open('popup.php?caption=Lucille Pohipe Eldridge\'s mother, Annie Sadegant Pohipe, a Boise Valley Shoshoni. Photo courtesy of Eldridge.&z=/photogallery/images/image34.jpg&width=640&height=869&title=Sacajawea','photopopup','width=640,height=869,directories=no,location=no,menubar=no,scrollbars =no,status=no,toolbar=no,resizable=no,screenx=150,screeny=150');return false">image34</a>
The uberfrustrating thing is that this code works like a peach(identical less the apostrophe and escape character):
<a href="#" onclick="window.open('popup.php?caption=Lucille Pohipe Eldridges mother, Annie Sadegant Pohipe, a Boise Valley Shoshoni. Photo courtesy of Eldridge.&z=/photogallery/images/image34.jpg&width=640&height=869&title=Sacajawea','photopopup','width=640,height=869,directories=no,location=no,menubar=no,scrollbars =no,status=no,toolbar=no,resizable=no,screenx=150,screeny=150');return false">image34</a>
If you can solve this problem for me, you will win one of two prizes. The first: exclusive land and water rights to the entire Caribbean. The second: my gratitude and respect. The only way to find out what you win is to reply! Good luck!
Paul Jr
11-17-2003, 06:08 PM
I believe you would place a backslash "\" before the punctuation in question.
I'm not sure if you've tried this or not...
n8guy
11-17-2003, 06:17 PM
Just so you know, when I posted that popup URL deal, the escape character did not show up. Just imagine a backslash before the apostrophe and you'll be set.
n8guy
11-17-2003, 06:21 PM
In case I didn't answer completely enough in that last post, yes, I have tried that (the backslash). Thank you for the suggestion.
Paul Jr
11-17-2003, 06:27 PM
I also tried that as soon as I posted, and it didn't work for me either. Which is odd -- Peep this. (http://www.w3schools.com/js/js_guidelines.asp)
n8guy
11-17-2003, 06:39 PM
I might be missing the gist of what you were saying about that link to the W3, but in case you were referring to the statement about open symbols ("Open symbols, like ( { [ " ', must have a matching closing symbol, like ' " ] } )."), I slapped another escaped apostrophe in the phrase and still came up empty-handed.
This is getting kinda crazy. It seems like it should work, and yet it doesn't... Paul Jr, thanks for your comments. Any other suggestions? Anyone?
Paul Jr
11-17-2003, 06:51 PM
Actually, I was refering to the part where it says;
Insert Special Characters
You can insert special characters (like " ' ; &) with the backslash:
document.write ("You \& I sing \"Happy Birthday\".")
The example above will produce this output:
You & I sing "Happy Birthday".
You can use &#39; and it will become ' and you can use &quot; and it will become " if you render it as HTML markup...
[J]ona
n8guy
11-18-2003, 10:30 AM
Paul, thanks for that link. I had researched it and discovered that already, but it's always good to double-check.
Jona, thank you also for your suggestion. I had already tried that solution as well. When I use the HTML codes (e.g. '), the JS link dies at the semi-colon, presumably because it missed the code altogether and sees the semi-colon as the end of the statement. Frustrating...
Any more comments are welcome... I have exhausted my knowledge on the subject. In case you are interested and would like to take a look at what's going on (although it may change as I mess with it), here is the URL for the page:
http://sacajawea.idahostatesman.com/photogallery/index.php
I have been messing with image 34 and not using the titles/descriptions for the others yet, as I am trying to isolate and fix the problem. Again, please let me know if you have any suggestions.
You guys/gals rock!
Paul Jr
11-18-2003, 12:47 PM
Originally posted by n8guy
Paul, thanks for that link. I had researched it and discovered that already, but it's always good to double-check.
Jona, thank you also for your suggestion. I had already tried that solution as well. When I use the HTML codes (e.g. '), the JS link dies at the semi-colon, presumably because it missed the code altogether and sees the semi-colon as the end of the statement. Frustrating...
From the statement which I have italicized, I am assuming what Jona suggested does not work because the semi-colon is interpreted as the end of the statement, thus screwing up the whole thing, correct?
If so, have you tried removing the semi-colon? The characters still show up without it -- I just checked that out -- and with the removal of of the semi-colon, it should not screw up your link.
n8guy
11-18-2003, 05:15 PM
Well guys, it looks like I solved the problem (although it was exceptionally painful). I still have to think through it, but it has to do with reprocessing the & quot; (") or the & acute; (') when it has to be used in another JavaScript URL (I know that there is no space after the ampersand, I just had to do that so it would show up in my post ).
This doesn't make a whole lot of sense to me, as I think JavaScript should just see & quot; as & quot;, not as " (leave it to the HTML to do that), but I guess it will see things how it wants to. I might even be wrong on that - too much time looking at the same code for me to make sense of it right now.
Anyway, thanks a lot for your help, and since two of you helped me, by definition, I cannot give both of you exclusive land and water rights to the entire Caribbean. Instead, you do have my gratitude and respect. Thanks a lot. It's great to have this forum as a resource.
n8guy
11-18-2003, 05:17 PM
Oh, also, removing the semi-colon didn't work. This problem, unfortunately, was much more deeply seeded than that... Thanks for the suggestion though!
Glad I could be of help.
By the way, you can use &quot; without it showing up as " by using &amp;quot;
[J]ona
Scriptage
11-19-2003, 03:15 AM
er....
Why dont you just escape the string you want to pass?
<script>
var string = "some 'Special' Characters for you here..$&%£@#";
var escaped = escape(string);
alert("The string when escaped is: " + escaped + "\nThis will pass in a query string");
</script>
n8guy
11-19-2003, 06:22 PM
Jona, thanks for the pointer!
Scriptage, that's cool. Thanks a lot for that function. I have never heard of it before. I will try to keep it in mind.
Thanks everyone for the help. Problem solved! :)