This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Webmaster forum > December 2005 > Perl/Javascript problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Perl/Javascript problem
|
|
| Ed Jay 2005-12-27, 3:32 am |
| Hi, ya'll:
I've got a situation I can't fathom.
I have a simple js function:
var region = new Array();
var region = new Array();
region["11"]="the upper-outer quadrant";
region["13"]="the upper-inner quadrant";
..
function decodeRegion(score,target1) {
if (score > 100) {score -= 100;}
mV = score.toString(10);
document.getElementById(target1).innerHTML = region[mV];
}
In a plain vanilla HTML page, I call the above with either an
onLoad="decodeRegion(11,'insert_here') or with a checkbox using the same
syntax, but with an onClick event, e.g., as follows:
<input type=checkbox onClick="decodeRegion(11,'insert_here');">ClickMe
<span id="insert_here"></span>.
Either the onLoad or onClick events work fine; however, when I create then
HTML page wirth Perl, upon calling exactly the same function (cut and
paste and adding appropriate escapes ''), I get an error. Using Opera,
the js console error displayed is:
ReferenceError message: Statement on line 1: Reference to undefined
variable: decodeRegion.
In IE, I get 'object expected' error.
What is happening, and what can I do to resolve the issue?
TIA,
--
Ed Jay (remove M to respond by email)
| |
| Ed Jay 2005-12-27, 3:32 am |
| Jump to follow up, below...
Ed Jay <edMbj@aes-intl.com> wrote:
>Hi, ya'll:
>
>I've got a situation I can't fathom.
>
>I have a simple js function:
>
>var region = new Array();
> var region = new Array();
> region["11"]="the upper-outer quadrant";
> region["13"]="the upper-inner quadrant";
> ..
>
>function decodeRegion(score,target1) {
> if (score > 100) {score -= 100;}
> mV = score.toString(10);
> document.getElementById(target1).innerHTML = region[mV];
>}
>
>In a plain vanilla HTML page, I call the above with either an
>onLoad="decodeRegion(11,'insert_here') or with a checkbox using the same
>syntax, but with an onClick event, e.g., as follows:
>
><input type=checkbox onClick="decodeRegion(11,'insert_here');">ClickMe
><span id="insert_here"></span>.
>
>Either the onLoad or onClick events work fine; however, when I create then
>HTML page wirth Perl, upon calling exactly the same function (cut and
>paste and adding appropriate escapes ''), I get an error. Using Opera,
>the js console error displayed is:
>
>ReferenceError message: Statement on line 1: Reference to undefined
>variable: decodeRegion.
>
>In IE, I get 'object expected' error.
>
>What is happening, and what can I do to resolve the issue?
>
Follow up:
I should have mentioned that I'm using a linked external javascript file.
I also just discovered if I put the function and array on the HTML page
generated by my PERL script, it works. WT...?
--
Ed Jay (remove M to respond by email)
| |
| John Bokma 2005-12-27, 3:32 am |
| Ed Jay <edMbj@aes-intl.com> wrote:
> Either the onLoad or onClick events work fine; however, when I create
> then HTML page wirth Perl, upon calling exactly the same function (cut
> and paste and adding appropriate escapes ''),
Does your PERL script use:
use strict;
use warnings;
if not, add them.
Also, if you output several lines of something, use:
print <<'EOT';
......
......
......
......
EOT
with single qoutes around EOT you don't have to escape a thing.
If you want string interpolation to work, use "" around EOT, e.g.
my $msg = 'hello, world!';
print <<"EOT";
.....
.....
$msg
.....
EOT
Make sure there is *nothing* after the ending EOT (which is just a random
name, you can probably think up a better end of text marker), just a
return.
Common mistakes: - white space other then end of line after EOT
- a ; after EOT
(the ending one I mean).
--
John PERL SEO tools: http://johnbokma.com/perl/
or have them custom made
Experienced (web) developer: http://castleamber.com/
| |
| Ed Jay 2005-12-27, 3:33 am |
| John Bokma <john@castleamber.com> wrote:
>Ed Jay <edMbj@aes-intl.com> wrote:
>
>
>Does your PERL script use:
>
>use strict;
>use warnings;
Yes.
>
>if not, add them.
>
>Also, if you output several lines of something, use:
I'm not. Short lines.
>
>print <<'EOT';
>.....
>.....
>.....
>.....
>EOT
>
>with single qoutes around EOT you don't have to escape a thing.
>
>If you want string interpolation to work, use "" around EOT, e.g.
>
>my $msg = 'hello, world!';
>
>print <<"EOT";
>....
>....
>$msg
>....
>EOT
>
>
>Make sure there is *nothing* after the ending EOT (which is just a random
>name, you can probably think up a better end of text marker), just a
>return.
>
>Common mistakes: - white space other then end of line after EOT
> - a ; after EOT
>
>(the ending one I mean).
Everything looks fine, codewise. Using exactly the same syntax, but
including the js and array on the generated page works fine. It's only
when I link to an external js file do I run into the problem. So...I now
have the js on the created page.
Thanks.
--
Ed Jay (remove M to respond by email)
| |
| John Bokma 2005-12-27, 6:28 am |
| Ed Jay <edMbj@aes-intl.com> wrote:
> Everything looks fine, codewise. Using exactly the same syntax, but
> including the js and array on the generated page works fine. It's only
> when I link to an external js file do I run into the problem. So...I
> now have the js on the created page.
Odd, odd. I thought that somehow you got PERL to interpolate something
that it shouldn't.
--
John PERL SEO tools: http://johnbokma.com/perl/
or have them custom made
Experienced (web) developer: http://castleamber.com/
| |
| Jerry Stuckle 2005-12-27, 7:03 pm |
| Ed Jay wrote:
> Hi, ya'll:
>
> I've got a situation I can't fathom.
>
> I have a simple js function:
>
> var region = new Array();
> var region = new Array();
> region["11"]="the upper-outer quadrant";
> region["13"]="the upper-inner quadrant";
> ..
>
> function decodeRegion(score,target1) {
> if (score > 100) {score -= 100;}
> mV = score.toString(10);
> document.getElementById(target1).innerHTML = region[mV];
> }
>
> In a plain vanilla HTML page, I call the above with either an
> onLoad="decodeRegion(11,'insert_here') or with a checkbox using the same
> syntax, but with an onClick event, e.g., as follows:
>
> <input type=checkbox onClick="decodeRegion(11,'insert_here');">ClickMe
> <span id="insert_here"></span>.
>
> Either the onLoad or onClick events work fine; however, when I create then
> HTML page wirth Perl, upon calling exactly the same function (cut and
> paste and adding appropriate escapes ''), I get an error. Using Opera,
> the js console error displayed is:
>
> ReferenceError message: Statement on line 1: Reference to undefined
> variable: decodeRegion.
>
> In IE, I get 'object expected' error.
>
> What is happening, and what can I do to resolve the issue?
>
> TIA,
>
What happens if you compare the HTML source between the two pages?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
| |
| Ed Jay 2005-12-27, 7:03 pm |
| Jerry Stuckle <jstucklex@attglobal.net> wrote:
>Ed Jay wrote:
>
>What happens if you compare the HTML source between the two pages?
The HTML page that works is different than the one generated by Perl. I'll
try it today. Thanks for the idea.
--
Ed Jay (remove M to respond by email)
| |
| Ed Jay 2005-12-27, 7:04 pm |
| John Bokma <john@castleamber.com> wrote:
>Ed Jay <edMbj@aes-intl.com> wrote:
>
>
>Odd, odd. I thought that somehow you got PERL to interpolate something
>that it shouldn't.
Problem solved. There was another script in the linked file that was
problematic. Had nothing to do with what I was trying to do, but it killed
all subsequent function calls. My app comprises several Perl-generated
HTML pages. The errant function is used on an early page and it's error
wasn't noted.
Thanks for your help.
--
Ed Jay (remove M to respond by email)
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|