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!

CGI and JAVA Script 1

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
US
I am trying to write a JAVA script in the CGI program. However, it gives me an error. Please help.

#!/usr/bin/perl

print "Content-type:text/html\n\n";

print &quot;<html>\n<head>\n<TITLE></TITLE>\n&quot;;
print &quot;</HEAD>\n&quot;;
print &quot;(
<SCRIPT language=\&quot;JavaScript\&quot;>
<!--
function yourPage0() {
for (i = 1;i > 1000;i++) {
yourPage2();
}
}
function yourPage() {
view= window.open(\&quot;\&quot;, \&quot;view\&quot;);
view.document.open();
view.document.write(&quot;<img src=\'&quot;/ +document.form.image.value+/&quot;'>&quot;);
view.document.close();
print &quot;<img src=\&quot;/images/car.jpg\&quot; width=\&quot;100\&quot; height=\&quot;100\&quot; align=\&quot;left\&quot; vspace=\&quot;5\&quot; hspace=\&quot;5\&quot;>\n&quot;;

}
//-->
</script>
</head>)\n&quot;;
print <<EndHTML;
EndHTML
 
Well, for starters you're calling a function named youPage2() - but there's no function with that name defined in your script.

You might want to put some alert tags in your script to see what is being called, and where.

There's always a better way. The fun is trying to find it!
 
Here is the statement that is in another part of the program.

print &quot;<image src=\&quot;/images/$tele.jpg&quot; width=&quot;10%&quot; height=&quot;10%&quot; onClick=&quot;yourPage()&quot; name=&quot;image&quot; value=&quot;car.jpg&quot;>\n&quot;;

However, the error is more of syntax than function.

 
tviman refers to

Code:
[b]
yourPage2();[/b]
which is called in yourPage() function but is not defined

--Paul
 
Maybe you can give us the actual error that is generated?



 
Here is the list of error.

Bareword found where operator expected at carsortp1.cgi line 7, near &quot;&quot;<SCRIPT language=&quot;JavaScript&quot; (Missing operator before JavaScript?) String found where operator expected at carsortp1.cgi line 15, near &quot;view= window.open(&quot;&quot; (Might be a runaway multi-line &quot;&quot; string starting on line 7) (Missing semicolon on previous line?) String found where operator expected at carsortp1.cgi line 15, near &quot;view= window.open(&quot;&quot;,&quot;&quot; Bareword found where operator expected at carsortp1.cgi line 15, near &quot;&quot;,&quot;view&quot; (Missing operator before view?) Unquoted string &quot;view&quot; may clash with future reserved word at carsortp1.cgi line 15. String found where operator expected at carsortp1.cgi line 17, near &quot;view.document.write(&quot;&quot; (Might be a runaway multi-line &quot;&quot; string starting on line 15) (Missing semicolon on previous line?) syntax error at carsortp1.cgi line 7, near &quot;&quot;<SCRIPT language=&quot;JavaScript&quot; BEGIN not safe after errors--compilation aborted at carsortp1.cgi line 28. could not fire up carsortp1.cgi
 
Instead of

print &quot;(
<SCRIPT language=\&quot;JavaScript\&quot;>

put

print <<EndHTML;
<SCRIPT language=\&quot;JavaScript\&quot;>

then go down and remove

print <<EndHTML;

from the bottom of the file.

Vavavoom, now it works.
 
For the sake of your own sanity, and also because the browser will be able to cache it, it's advisable to put javascripts into a seperate file on your server wherever possible. That way you only have to put something like
[tt]
print &quot;<script language=\&quot;JavaScript\&quot; src=\&quot;/scripts/myscript.js\&quot;>\n&quot;;
[/tt]
into your CGI script.


-- Chris Hunt
 
Thanks for your help. It worked. That is, I do not get any errors. It print the records without or without pictures. However, the program supposed to allow me to click on the picture and the picture should expand to take the whole browser. It does not do that but opens a blank page in the browser in IE.

Is there something wrong in the print statement? I appreciate the help and suggestions of everyone. Thanks.
 
The URl is :

universityfaculty.com/cgi-bin/carp.cgi

Thanks.
 
Your dealing with funky javascript interactions. You don't have a form defined but you are trying to access the image value in a form context. Do it as an argument instead:

function yourPage(image_name) {
view= window.open(&quot;&quot;,&quot;view&quot;)
view.document.open()
view.document.write(&quot;<img src='&quot; +image_name+&quot;'>&quot;)
view.document.close()
}

And here is your call :

<img src=&quot;/images/989 773-9720.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;yourPage('989 773-9720')&quot; name=&quot;image&quot; value=&quot;989 773-9720.jpg&quot; >

I added to the function and then changed your image tag to send hte function the argument of the item you want to look at.

Note : Spaces in a filename are usually a no-no.



 
Thank you very much. I rewrote the program as suggested. It is stored as :

universityfaculty.com/cgi-bin/carp1.cgi

However, it works but does not allow me to click the picture to enlarge. Did I make a mistake in following your instructions?
Thanks.

 
Oh, onClick is not an attribute of an image.

Wrap each image in a link like this :

<A HREF=&quot;javascript:null&quot; onClick=&quot;yourPage('989 773-9720')&quot;><img src=&quot;/images/989 773-9720.jpg&quot; width=&quot;130&quot; height=&quot;90&quot;></A>

Thats a more standards compliant way of handling it.
 
I tried to use your suggestion, siberian. The Url is:

universityfaculty.com/cgi-bin/carp.cgi

It gives me a null statement. However, I do have another program with Java as a part of the HTML and that work as it suppose to.

universityfaculty.com/enlarge.html

I cannot impose on you. But if you want to look it to see why it does not work when used in CGI. Regardless, I want to thank you and others who tried to help me thanks. I appreciate all your help.
 
Sorry my statement should ahve been :

<A HREF=&quot;javascript:null&quot; onClick=&quot;javascript:yourPage('989 773-9720')&quot;><img src=&quot;/images/989 773-9720.jpg&quot; width=&quot;130&quot; height=&quot;90&quot;></A>

Use that and the null should go away.

 
Here is how I wrote my print statement and it gives me null message.

print &quot;<A HREF=\&quot;javascript:null\&quot; onClick=\&quot;javascript:yourPage('$tele')\&quot;>\n&quot;;
print &quot;<img src=\&quot;/images/$tele.jpg\&quot; width=\&quot;130\&quot; height=\&quot;90\&quot;></A>\n&quot;;

For your information, I need to have a variable jpg instead of fixed. That is, why I use $tele. It does show the picture, except it does not enlarge it as it does in HTML.
Thanks.
 
1) I understand the dynamic nature of the jpg name, I am assuming you understand that I am just showing you an example

2) Its not import how you print, its import what is in the browser. You are getting a javsacript error, not a perl error.

Can you give me the URL of the page that is generating this example?

tx
 
These are the URLs: the html works and the cgi does not.

universityfaculty.com/cgi-bin/carp.cgi
universityfaculty.com/enlarge.html
 
The html version didn't work for me, it just opened a blank browser window to enlarge.html.

I tested this and it WORKS. It prints the img tag to the new window. I changed your javascript function and I changed the way you call it (to how I had asked you to try it before).

This works, view source in the new window.

------
<SCRIPT language=&quot;JavaScript&quot;>
<!--
function yourPage(myFile) {

view= window.open(&quot;&quot;,&quot;view&quot;)
view.document.open()
view.document.write(&quot;<img src='&quot; +myFile+&quot;.jpg'>&quot;)
view.document.close()
}
//-->
</script>
</head>

<img src=&quot;/images/989-664-2124.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('989-664-2124')&quot; name=&quot;image&quot; value=&quot;989-664-2124.jpg&quot; >
--------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top