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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript onload in perl cgi script

Status
Not open for further replies.

ibjdt

Programmer
Nov 25, 2002
63
i an using (or want to use) a js script to sort a table created by a perl cgi script.

the js script requires an onload in the body tag

Code:
onload='initTable("table0");'

then the table is id'd as table0

Code:
<table border="1" cellspacing="2" cellpadding="2" width=100% ID="table0">


i create the table contents with perl
print the header to the screen

Code:
<HTML>
<HEAD>
<link href="../../../styles.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY onLoad='initTable("table0");' BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<SCRIPT SRC="sortTable.js">
</SCRIPT>

<CENTER>
<img src="../../../banner.gif" width="724" height="86"><br></center>

print the table
print the footer

when the cgi page loads, i get a js error

Code:
object expected (code 0)

the line reference is the body tag where the onload is.

any ideas?? if i copy the source from the error'd page, i can save it as an html page and it works fine.

thanks for the help.
 
Move the script tags above the onLoad event
Code:
<SCRIPT SRC="sortTable.js">
</SCRIPT>
<BODY onLoad='initTable("table0");' BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">


cigless ...
 
thanks, but i failed to mention i have tried that along with mixing and matching ' and ", changing the table id name, etc.

i also changed the onload to

Code:
onLoad='alert("hello"); initTable("table0");'

and the alert came up, but the script didn't perform.
thanks again.
 
Can you place this page at a temporary url and give us a link?

May shorten the path to a solution.

Thanks,
 
i have uploaded examples:

1. the relevant part of the cgi script -
2. the header file with onload event and calls the js script -
3. the js sorting script -
4. a working example of html page using sortTable -

the cgi gathers data, prints the header, prints the gathered data, prints the footer.
#4 above is a nearly exact representation of the cgi output.

however, as explained before, when the cgi puts it all together, i receive a js error.
the source shows all the parts to be in place, but it doesn't work.

i hope this helps. let me know if you need more info.
i appreciate any and all help.
 
looks like the subs that print the header and footer are maybe only printing the first line of the files:

sub h {
open(DATA,"cgi-bin/data/dcr/header.html");
print <DATA>;
close(DATA);
}

sub f {
open(DATA,"cgi-bin/data/dcr/footer.html");
print <DATA>;
close(DATA);
}

try like this

sub h {
open(DATA,"cgi-bin/data/dcr/header.html");
print while (<DATA>);
close(DATA);
}

sub f {
local $/ = undef;
open(DATA,"cgi-bin/data/dcr/footer.html");
print while (<DATA>);
close(DATA);
}

 
Hi

I think this belongs to the JavaScript forum. And you did not shared any detail with us. Your sample works fine on my Mozilla 1.0.1, Mozilla 1.8b, Phoenix 0.5, Explorer 5.0 and Explorer 6.0. After removing the checkbrowser() call in the sortTable.js file ( line 210 ), works even on Opera 8.01 and Konqueror 3.4.0. Fails only on Konqueror 3.0.3. The Explorers runs on Windows '98, all others on Linux.

So what is your problem exactly ?

Feherke.
 
please note:

this line should not have been in the code I posted:

local $/ = undef;

sorry for any confusion.

 
Where does the sortTable.js script live? It seems to me that this line:
Code:
<SCRIPT SRC="sortTable.js">
</SCRIPT>
when appearing in a cgi-generated page is going to look in yourdomain.com/cgi-bin/sortTable.js . But being in the cgi-bin, it'll try to interpret that server-side first, resulting in errors.

Use an absolute path instead (your script being in yourdomain.com/scripts/sortTable.js):
Code:
<SCRIPT SRC="/scripts/sortTable.js">
</SCRIPT>

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
I'm probably talking rubbish but can't you get Perl to sort the table... after all Perl is generating it!?


Kind Regards
Duncan
 
thanks for all the help especially Chris Hunt.

i feel really stupid saying this, but the path to the js was the problem. i have always used '/dirname/scriptname.js' style paths, but this one for some reason has required the full path '
i use perl/js combo a lot and i don't remember running into that before. oh well, i guess there is a first time for everything.

thanks again for the help.
 
Apache, depending on it's configuration can refuse to serve image files from the cgi-bin directory (Apache assumed), so it might be a similar problem with script files

Just a thought, worth a looksee in the logs at any rate

HTH
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top