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
 
I want to thank you, siberian, for helping me with all the suggestions. However, it seems that all the statements you suggest work under HTML code. I already have an HTML code that works fine. In my previous messages, I listed that URL :

universityfaculty.com/enlarge.html

for you to see. That works.

My problem is how to rewrite the same code in cgi to work. The same code and your code do not work properly in cgi. That is where I need help. I have created a cgi program with your code:

universityfaculty.com/cgi-bin/carp1.cgi

Please check, if you want, and see that it does not work. The actual code in the file is:

#!/usr/bin/perl

print &quot;Content-type:text/html\n\n&quot;;

print <<EndHTML;
<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>
EndHTML

use CGI;
$query = new CGI;

open(INF, &quot;<car.out&quot;) or dienice(&quot;Couldn't open auto.out for reading: $! \n&quot;);
@kites = <INF>;
close (INF);

foreach $i (@kites) {
chomp ($i);
($name,$add,$city,$state,$zip,$make,$photo,$model,$color,$mile,
$eyear,$price,$email,$tele,$time,$comment1,$month,$day,$year)=split(/\|/, $i);
print &quot;<img src=\&quot;/images/$tele.jpg\&quot; width=\&quot;130\&quot; height=\&quot;90\&quot; onClick=\&quot;javascript:yourPage('$tele')\&quot; name=\&quot;image\&quot; value=\&quot;$tele.jpg\&quot; >&quot;;

}

print <<EndHTML;
EndHTML

sub dienice {
my($msg) = @_;
print &quot;<h2>Error</h2>\n&quot;;
print $msg;
exit;
}
 
It worked for me. The images are broken since they do not exist on my server. Additionally the page that opens when I click has a broken image since that server also does not exist on my server.

You can see my output at :
What specifically is the error you get, I can not replicate any errors.

This is the output of the CGI (some debug thrown in, ignore it)

<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>
Name is $name,$add,$city,$state,$zip,$make,$photo,$model,$color,$mile,<br><img src=&quot;/images/.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('')&quot; name=&quot;image&quot; value=&quot;.jpg&quot; >
Name is $eyear,$price,$email,$tele,$time,$comment1,$month,$day,$year<br><img src=&quot;/images/.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('')&quot; name=&quot;image&quot; value=&quot;.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >

Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is 1<br><img src=&quot;/images/14.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('14')&quot; name=&quot;image&quot; value=&quot;14.jpg&quot; >
Name is <br><img src=&quot;/images/.jpg&quot; width=&quot;130&quot; height=&quot;90&quot; onClick=&quot;javascript:yourPage('')&quot; name=&quot;image&quot; value=&quot;.jpg&quot; >

This is my input file

1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19
 
I wanted my program in HTML to work in CGI. All the suggestions so far did not solve my problem. Thanks for your help. I do not want to waste anyone's time anymore. Thanks for your help.
 
Dude, I AM RUNNING YOUR CGI ON MY SERVER

It GENERATES this html.

I don't get what your after, it works.
 
As siberian says he is running your CGI on his server - not an HTML page - i.e. the HTML is being dynamically generated. If I run universityfaculty.com/cgi-bin/carp1.cgi it does work. Run it yourself - a blank page appears - then [red]view source[/red] and you will see the invisible JavaScript...

[blue]<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>[/blue]

Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top