473,390 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Javascript intrepreting an apostrophe as a delimiter while displaying a perl variable

I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\"
onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"

http://www.epa.gov/cgi-bin/airnow.cg...splay=FORECAST

javascript error:
missing ; before statement.
window.status='OZONE Forecast For Coeur d'Alene, ID';return true
Jul 20 '05 #1
3 12848
I had a similar problem with a PHP mailing tool I wrote where apostrophes in
a text interfered with the apostrophes in the form elements (value="$text").
I made a workaround with urlencoding and urldecoding the string.

One problem with this is that if you urlencode with Perl it is not sure that
the decodeURI function in javascript decodes it properly, you have to test
that (I am not familiar with Pearl, it does not work with PHP). I would try
adding a script in the HTML head, the output should look something like:

var jsLinkCity = encodeURI($LinkCity)

and then pass the variable jsLinkCity with the Popup function and decode it
again in the head of the popup window file.

You can also encode and decode it with Perl, but probably not encode it with
one and decode it with the other.

hth
Markus
"Jeanne" <br***********@epa.gov> schrieb im Newsbeitrag
news:61*************************@posting.google.co m...
I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\" onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"

http://www.epa.gov/cgi-bin/airnow.cg...splay=FORECAST

javascript error:
missing ; before statement.
window.status='OZONE Forecast For Coeur d'Alene, ID';return true


Jul 20 '05 #2
> var jsLinkCity = encodeURI($LinkCity)

and then pass the variable jsLinkCity with the Popup function and decode it again in the head of the popup window file.

You can also encode and decode it with Perl, but probably not encode it with one and decode it with the other.


Actually, I don't think it would be a good idea to URL encode it, since the
only characters that'd stress out Javascript in a variable value would be
apostrophe and in certain cases backslash (like if for some reason a value
contained (and was supposed to contain) \' or \\ or \n). If you just use cgi
to replace every instance of \ with \\ and ' with \' your Javascript
variables will be correct (at least AFAIK ;)

Daniel
Jul 20 '05 #3
> I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\" onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"


It bites that JavaScript does not have nesting string delimiters. Rebol does
(www.rebol.com), and I think that is quite civilized.

You need a slashify function which will insert a backslash before every quote,
single quote, and backslash in a string. Using such a function, your code will
get a lot easier to read, too.

http://www.crockford.com/javascript/remedial.html

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: john brown | last post by:
I'm new to perl programming and would like some help if at all possible. I'm trying to make a simple script where I can input a filename. To be exact something like "/home/song1.mp3". I want to...
2
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes...
22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
1
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call...
1
by: Rose | last post by:
Hi all, I'm trying to create a clickable link, but the pesky apostrophe is preventing the link from getting displayed properly. I'm displaying the contents of a folder (with contains the...
1
by: Tufty | last post by:
Hi, I have a webpage that lets the user upload an image. This is the posted to a perl script as a form var. The data is stored in SQL 2005 (as the new image object). I now need to get it back...
2
by: pleaseexplaintome | last post by:
Hi I have the following perl/cgi script snippet. The goal of this script is to pass a javascript variable to perl where it can be re-used later. Any help is appreciated, Thanks ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.