Click to See Complete Forum and Search --> : how to translate javascript to cgi?
bullzzz
12-15-2002, 12:40 AM
Hi everyone,
I have a problem trying to figure out how to change a javascript here to cgi script.
----------- javascript --------------------
<li><a href="delay.htm" onClick="pageClick('FILE101');return false">File 101</a></li>
function pageClick(Page){
var w = window.open();
w.document.open();
w.document.write("<html><head><title>Document with Frames</title></head><frameset rows=\"51,*\" framespacing=\"0\" frameborder=\"yes\" border=\"0\"><frame name=topFrame src=\"searchPanel.html\" scrolling=\"no\" noresize><frame name=body src=\""+Page+".html\"></frameset></html>");
w.document.close();
}
--------------------------------------------
How do I convert the function pageClick(Page) into a CGI subroutine? Can I use the print statement?
cheers.
jeffmott
12-15-2002, 02:05 AM
Yes, you can output HTML just by printing it to STDOUT.
print "Content-Type: text/html\n\n";
print q`
<!-- HTML HERE -->
`;
However, you cannot open or close windows with any server-side language.
bullzzz
12-15-2002, 03:22 AM
Can i do this?
print "<br><a href=\"$URLS{$file}\" target=\"blank\"
onClick="<html><head><title>Document with Frames</title></head>
<frameset rows=\"51,*\" framespacing=\"0\" frameborder=\"yes\" border=\"0\"><frame name=topFrame src=\"searchPanel.html\" scrolling=\"no\" noresize><frame name=body src=\"FILE101.HTML\"></frameset></html>" >$sometext</a>\n"
:confused:
jeffmott
12-15-2002, 04:43 AM
You have some syntax errors (missed some double quotes to escape) and you should make sure the HTML you generate is valid, but otherwise yes. You can output JavaScript with the page.
bullzzz,
I'm not an cgi freak (only PHP), but I think this works:
print '<script language=javascript>
function pageClick(Page){
var w = window.open();
w.document.open();
w.document.write("<html><head><title>Document with Frames</title></head><frameset rows=\"51,*\" framespacing=\"0\" frameborder=\"yes\" border=\"0\"><frame name=topFrame src=\"searchPanel.html\" scrolling=\"no\" noresize><frame name=body src=\""+Page+".html\"></frameset></html>");
w.document.close();
}
</script>';
print "<body><li><a href=\"delay.htm\" onClick=\"pageClick('FILE101');return false\">File 101</a></li></body>";
Try this, hope it works
Swon
Charles
12-15-2002, 08:05 AM
bullzzz, a couple of things about Perl:
Perl has quite a number of different kinds of quotes (I can think of five kinds at the moment) and they all work differently. Single quotes are just like the quotes in JavaScript except that they can enclose multi-line strings. Double quotes in Perl can only enclose single-line strings but they do variable substitution. One of the other kinds allows variable substitution with multi-line strings. Variable substitution takes a good bit of overhead, so it's good practice to use single quotes unless you need the double.
In Perl any character can be a quote character. The usual quote characters are by default, but you can make any character do the trick by preceding it with a q for a single quote or a qq for a double. Hence: q|I bite my thumb at thee!| or qq{Good night, sweet $princeString}. This is so that you never have to escape your quote characters.
You might find it helpful to use the ubiquitous CGI.pm module (http://theoryx5.uwinnipeg.ca/CPAN/data/perl/CGI.html). It keeps track of the form information that's passed to the script and it has a Perl-like syntax for generating HTML that keeps your document 'well formed' at least.
The script in your last posting above will not work. Can you explain exactly what it is that you are trying to do?
jeffmott
12-15-2002, 11:11 AM
Just a small correction from above.
Double quotes in Perl can only enclose single-line strings
Perl ignores white space. Any quote character can enclose any number of lines.
Charles
12-15-2002, 01:14 PM
I stand corrected. Thanks, jeffmott, for setting me straight.
bullzzz
12-16-2002, 10:32 AM
Thanks for the information everyone. Although I was a little confuse with some content, other than that, really glad that you guys offer to give some useful comments. Thanks a million to all you guys.
:D:D:D:D:D:D:D;)
cheers.