Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using javascript in a CGI in Perl

Using javascript in a CGI in Perl

Using javascript in a CGI in Perl

I am trying to get info from the user via a javascript prompt but when I run the script on a browser nothing happens.

Here is my code :

 use CGI;
 $co = new CGI;
 print "Content-type: text/html\n\n";
 print "<HTML>";
 print "<HEAD>";
 print "<TITLE>Formulaire de réception</TITLE>";

 print "<SCRIPT language=\"JavaScript\"> ";
 print "<!--hide";
 print " var yoururl = prompt(\"S.V.P. entrez ladresse IP ou le nom du router :\", \"http:\/\/ \");";
 print " if ( (yoururl==' ') ¦¦ (yoururl==null) )";
 print " {";
 print "   history.back(); ";
 print " }";
 print " else";
 print " {";
 print "   window.location=yoururl;";
 print " }";
 print "//--> ";
 print "</SCRIPT> ";
 print "</HEAD>";
 print "<BODY BACKGROUND=\"../Images/fondtpv.jpg\" NOSCROLL    SCROLL=\"no\" BGCOLOR=\"#000000\" TEXT=\"#FFFFFF\" LINK=\"#FF0000\" ALINK=\"#FF0FFF\">";
 print "</BODY>";
 print "</HTML>";

does javascript even work with Perl ??

RE: Using javascript in a CGI in Perl


 Java works with perl fine because the output is html. Your perl code looks fine to me and the java is in the right place but I don't know java that well. To avoid problems when printing java and html it's best to use a diiferent method than the stadard print ""; function. Try using
print qq


print <<ENDHTML;

the qq function will print html until it reaches the character that you put right after qq. So in this case the perl will print html until it gets to ~; unless you use somthing else like a pipe after qq. Then it will look like this print qq¦¦; ect..

 When using the above methods you don't need to escape the quotation marks " with a backslash ex. \". You  can just put the html as-is between the two lines.

 Also in the future while writing more complex scripts it's good practice to use the exit; function at the end of your scripts. That way it will prevent you scripts from looping.

 I don't think that in this case you need to use the CGI module also. And to read a users ip address you can use $ENV{'REMOTE_ADDR'}.


RE: Using javascript in a CGI in Perl

certainly javascript works from PERL....they are not really "working together".  I echo perlkid......you are simply using perl to write jscript.  If the jscript is well formed it will work.  You either have a jscript syntax problem or are trying a tedious (read error-prone) method to print it, as perlkid suggests.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close