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

No src for my JS, Mr. Perl Server?

Status
Not open for further replies.

SilverBean

Programmer
May 23, 2001
44
US
I've got a cgi file in cgi-bin. This needs to run get some data from the database and post in a table. I'm revisiting my javascript-ing days and as the user interacts with this data in table form little bits of script run. Actually I've got a few things that really jazz things up - so doing without would be a real downer right now.

This is the cgi file (simplified to demonstrate problem):

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use constant TRUE => 1;
use constant FALSE => 0;

print "Content-type: text/html\n\n";
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \" \n";

print "<HTML><HEAD>\n";
print "<meta http-equiv=\"content-type\" content=\"text/html;charset=iso-8859-1\">\n";
print "<TITLE>Hello</TITLE>\n";
print "<script type=\"text/javascript\" language=\"javascript\" src=\"chance.js\"></script>\n";
print "</HEAD><BODY>\n";

print "<form name=\"FormName\" action=\"(Empty Reference!)\" method=\"get\">\n";
print "<input type=\"checkbox\" value=\"checkboxValue\" name=\"chkPurchase\" ";
print "onclick=\"X1();\">\n";
print "</form>\n";


print "</HTML></BODY>";
#end of program

Problem is Perl(or somebody) does not like the src=. No matter what I put regardless of whether an actual file or not gives me errors. Gives me an object expected at line 58 Char 1. Which is the "<script type=" line. Want to try it? Try to check the box....go ahead......check the box.

Please be patient with netfirms they give the free sites low priority for cgi time you may get a try back message. Don't have to wait the full five minutes. No matter what I put for src= get the same error. Try a stupid non-existent file still error. Try the thing still error. I've tried this on my local Perl/CGI server and also my paid for real stuff at netfirms still same. Locally I'm running Apache probably older, but gotta believe the netfirms is a pretty up to date. Can't believe its quirking server thing. Seeing in IE V6.0 -- could it be a browser thing?

The kicker? If you have the capability to run the cgi locally. Give it a shot. When the browser brings up the CGI and you click on the check box error occurs on the page fine. Now do a view source save as htm. Then open it your browser and as a htm file(output of the cgi code) check the box thing works fine.

BTW: chance.js is

function X1()
{
window.alert("Hey you clicked on ");

}
Maybe I forgot some real simple JS thing?

My gut feeling is that its a Perl server thing. That is inherently when requests are made to access a file in the cgi-bin the server is really looking for cgi code. I even tried just renaming the file to cgi. I also tried changing the privileges of the JS RWE for everybody including my Uncle :)

On the other hand it looks like the src attribute is just not working which I can't believe did alot of searches haven't seen anything that obvious. Seems like double redundant to be coding JS in amongst my Perl with print statements. In line java for the above works fine, but I've got a good amount of JS to put in, and then if I do that make changes if I ever just want the JS stuff somewhere else I have to go back and weed it all out. So I'm just having a difficult time of passing this.

Any ideas?
 
your problem has nothing to do with perl. The src has to be a url, so if you use src="chance.js" the change.js file woul dhave to be in the cgi-bin, since it a relative url. The cgi-bin generally does not allow access, so put the change.js file in a folder that has and try using the full url:

src="
where "folder" is the name of the folder the change.js file is in.
 
Thanks for making me take a second look at that. Of course I was at a point where I would've tried anything so I'm glad you didn't mention something more detrimental to my health.

I understood the immediate thing and that I was asking the server to run JS code out of cgi-bin which I can understand is not allowed and confusing to the Server. In fact since initial post - it dawned on me to check logs files on my local Apache server and entries were made telling me scripts had to have #! in first line. I did that and then the error became can't spawn child or some such nonsense - so fine.

I had tried the full http thing. That is I mentioned above as http:/blahblah where blahblah was something that made sense like you mentioned. I thought I had seen this also fail, but in the heat of battle maybe I wasn't looking at exactly what I thought I was. I gave this a second try, actually a 6th and 7th try at this point and it did exactly what I wanted.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top