Gossamer Forum
Home : Products : DBMan : Customization :

JavaScript & CSS in perl script?

Quote Reply
JavaScript & CSS in perl script?
Having trouble [errors] running JavaScript and CSS within the html.pl ...
I've run certain JavaScripts on other perl scripts with no issues.
[Probably the pipe symbols...]

Recommendations? Workarounds?

Thanks.
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
We do a mixture of external and internal JS & CSS. Probably has to do with your form name?

If you are using something like document.form.field.value
then you need to have <form name="form"> in all of your form tags (which I believe in html.pl not all are named).

What kind of errors are you getting?
Quote Reply
Re: [Watts] JavaScript & CSS in perl script? In reply to
Error:
"database internal error. Please enable debugging to view."

The above error is definately caused from the insertion of JavaScript code in the <head> area. The code is as follows [sorry, this is a bit long] :

<!-- Begin NavTree code-->
<script language="Javascript">
<!-- Hide script from old browsers
document.WM = new Object();
document.WM.menu = new Object();
document.WM.menu.dropdown = new Array();
function WM_initializeToolbar(){
var i;
if (document.all){
for(i = 0; i < document.all('container').all.length; i++){
if ((document.all('container').all.className == 'header') ||
(document.all('container').all.className == 'links')){
document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= document.all('container').all;
}
}
} else if (document.getElementsByTagName && document.getElementById){
var contained =
document.getElementById('container').getElementsByTagName('div');
for(i = 0; i < contained.length; i++){
if ((contained.getAttribute('class') == 'header') ||
(contained.getAttribute('class') == 'links')){
document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= contained;
}
}
}
}
function WM_collapse(item){
if(document.WM.menu.dropdown.length){
if (document.WM.menu.dropdown[item + 1].style.display == 'none'){
document.WM.menu.dropdown[item + 1].style.display = '';
if(document.WM.menu.dropdown[item].id == 'growthtrac'){
document.images[document.WM.menu.dropdown[item].id +
'Img'].src = 'http://www.growthtrac.com/images/open_gray.gif';
} else {
document.images[document.WM.menu.dropdown[item].id +
'Img'].src = 'http://www.growthtrac.com/images/open_gray.gif';
}
} else {
document.WM.menu.dropdown[item + 1].style.display = 'none';
if(document.WM.menu.dropdown[item].id == 'growthtrac'){
document.images[document.WM.menu.dropdown[item].id +
'Img'].src = 'http://www.growthtrac.com/images/closed_gray.gif';
} else {
document.images[document.WM.menu.dropdown[item].id +
'Img'].src = 'http://www.growthtrac.com/images/closed_gray.gif';
}
}
}
}
function WM_imageSwap(daImage, daSrc){
var objStr,obj;
/*
WM_imageSwap()
Changes the source of an image.
Source: Webmonkey Code Library
(http://www.hotwired.com/...script/code_library/)
Author: Shvatz
Author Email: shvatz@wired.com
*/
// Check to make sure that images are supported in the DOM.
if(document.images){
// Check to see whether you are using a name, number, or object
if (typeof(daImage) == 'string') {
// This whole objStr nonesense is here solely to gain compatability
// with ie3 for the mac.
objStr = 'document.' + daImage;
obj = eval(objStr);
obj.src = daSrc;
} else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
daImage.src = daSrc;
}
}
}
// End the hiding -->
</script>
<!-- END NavTree code-->


The above code works fine elsewhere in the site. By the way, I have other JavaScript in the html.pl and not having any problems with that.

Thanks again.







Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
If I had to guess I'd say it's the pipes || that are causing your problem. Try changing the pipes to "or" and see if the script works. Or change your print delimiter.
Quote Reply
Re: [Watts] JavaScript & CSS in perl script? In reply to
Okay... I tried subsituting the word "or" for the "| |" pipes.
Still a problem. [Same error message, see first message at top.]

What's interesting is I'm using the same Java Script in my Links2.0 implementation and it works fine -- no errors.

Now, I know we're talking about two different applications, but I'm essentially doing the same thing, riight? -- inserting Java Script in a CGI script.

Comments please. Thanks.
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
Try changing

print qq| |

to

print qq~ ~;


...around the code.

Last edited by:

RedRum: Jan 21, 2002, 9:16 AM
Quote Reply
Re: [RedRum] JavaScript & CSS in perl script? In reply to
No good.

Replaced all "|" with "~" ... now getting error:

"database internal error. Please enable debugging to view."
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
Are you sure its the javascript causing the error?

If it is then changing | | to ~ ~ should do the trick.
Quote Reply
Re: [RedRum] JavaScript & CSS in perl script? In reply to
Actually, I forgot to mention in the previous post, the error occured without javascript -- changing the |'s to ~'s caused an error.

Just to confirm I understood you...
EXAMPLE
I changed this code:

print qq |
<html><head><title>$html_title - $page_title</title>
|;


To this code:
print qq ~
<html><head><title>$html_title - $page_title</title>


~;


Correct?


````````````````````````````````````````
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
Do you have an error log?

(Yeah that was correct).
Quote Reply
Re: [RedRum] JavaScript & CSS in perl script? In reply to
[error log]... No, I do not. Is that the "debug" option? Please explain.
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
No an error log is the sort you get from your webhost.

If you have a telnet or ssh account you can use that...

perl -c db.cgi
Quote Reply
Re: [RedRum] JavaScript & CSS in perl script? In reply to
Alright, just found something interesting:

I launched my db page WITHOUT the javascript [there were no errors] and did a viewsource on that page.

I noticed that two tags are missing from the html.pl :
</head>
<body>

Now, remember, this page displays normally, WITHOUT the above tags, with no errors !! [Evidentally, my db script has run fine with the missing tags.]

So, here's what I'm thinking... Perhaps the the javascript "needs" the head and body tags to function properly?

So... even if that is not the solution, I need to get those tags back in to the page. Any idea why they might be missing?
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
Post your html.pl file as an attachment so we can see what it is you're trying to do. If it works in links then it should work in dbman. I bet the answer will lie with the missing html tags. I imagine that somewhere you are missing a print tag or something.
Quote Reply
Re: [Watts] JavaScript & CSS in perl script? In reply to
Okay... I think we're closer. Those tags were indeed missing-- Might have been deleted before. I added the <body> and </head> tags.

The problem is definately here, in this javascript:

**************************
function WM_initializeToolbar(){
var i;
if (document.all){
for(i = 0; i < document.all('container').all.length; i++){
if ((document.all('container').all.className == 'header') ||
(document.all('container').all.className == 'links')){
document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= document.all('container').all;
}
}
} else if (document.getElementsByTagName && document.getElementById){
var contained =
document.getElementById('container').getElementsByTagName('div');
for(i = 0; i < contained.length; i++){
if ((contained.getAttribute('class') == 'header') ||
(contained.getAttribute('class') == 'links')){
document.WM.menu.dropdown[document.WM.menu.dropdown.length]
= contained;
}
}
}
}
**************************
Problem is with the pipes "||".

So... After testing, I found the javascript does not like "or" in place of the pipes [as suggested in an earlier post].

Also tried replacing all the CGI pipes "|" with "~" ... The html.db errored-out when I tried that.

Question: I need a workaround here. Looks like the pipes MUST stay in the javascript.

I've attached my html.pl [store_html.pl].

You'll notice a java error when you launch the page. That is due to the above javascript erroring out. [This particular javascript executes the nav tree menu in the left column. Everything else on the page works fine.]

As mentioned, the same javascripts work fine in links.

Thanks!
Quote Reply
Re: [jmueller] JavaScript & CSS in perl script? In reply to
As I understand it, perl has a tendency to interpret some of the syntax used in javascript code.

My way round this is to "wrap" the javascript up as a .js file, copy this to the server, then call it in the html.

The javascript can be left out of the html.pl file altogether.

This is particularly useful for menu scripts as a change to the js file is a global change.
-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.
Quote Reply
Re: [davidolley] JavaScript & CSS in perl script? In reply to
R E S O L V E D !!

Thanks to all who helped.
Solution: Moved javascript to a .js file. Simple.

Thanks again.