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

Using javascript in a CGI in Perl 1

Status
Not open for further replies.

darkom

Programmer
Apr 14, 2000
28
CA
I am trying to get info from the user via a javascript prompt but when I run the script on a browser nothing happens.<br><br>Here is my code :<br><br>&nbsp;use CGI;<br>&nbsp;$co = new CGI;<br>&nbsp;print &quot;Content-type: text/html\n\n&quot;;<br>&nbsp;print &quot;&lt;HTML&gt;&quot;;<br>&nbsp;print &quot;&lt;HEAD&gt;&quot;;<br>&nbsp;print &quot;&lt;TITLE&gt;Formulaire de réception&lt;/TITLE&gt;&quot;;<br><br>&nbsp;print &quot;&lt;SCRIPT language=\&quot;JavaScript\&quot;&gt; &quot;;<br>&nbsp;print &quot;&lt;!--hide&quot;;<br>&nbsp;print &quot; var yoururl = prompt(\&quot;S.V.P. entrez ladresse IP ou le nom du router :\&quot;, \&quot;http:\/\/ \&quot;);&quot;;<br>&nbsp;print &quot; if ( (yoururl==' ') ¦¦ (yoururl==null) )&quot;;<br>&nbsp;print &quot; {&quot;;<br>&nbsp;print &quot;&nbsp;&nbsp;&nbsp;history.back(); &quot;;<br>&nbsp;print &quot; }&quot;;<br>&nbsp;print &quot; else&quot;;<br>&nbsp;print &quot; {&quot;;<br>&nbsp;print &quot;&nbsp;&nbsp;&nbsp;window.location=yoururl;&quot;;<br>&nbsp;print &quot; }&quot;;<br>&nbsp;print &quot;//--&gt; &quot;;<br>&nbsp;print &quot;&lt;/SCRIPT&gt; &quot;;<br>&nbsp;print &quot;&lt;/HEAD&gt;&quot;;<br>&nbsp;print &quot;&lt;BODY BACKGROUND=\&quot;../Images/fondtpv.jpg\&quot; NOSCROLL&nbsp;&nbsp;&nbsp;&nbsp;SCROLL=\&quot;no\&quot; BGCOLOR=\&quot;#000000\&quot; TEXT=\&quot;#FFFFFF\&quot; LINK=\&quot;#FF0000\&quot; ALINK=\&quot;#FF0FFF\&quot;&gt;&quot;;<br>&nbsp;print &quot;&lt;/BODY&gt;&quot;;<br>&nbsp;print &quot;&lt;/HTML&gt;&quot;;<br><br>does javascript even work with Perl ??<br>
 
Yes,<br><br>&nbsp;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 &quot;&quot;; function. Try using <br>print qq<br>~<br>html...<br>~;<br><br>or <br><br>print &lt;&lt;ENDHTML;<br>html...<br>ENDHTML;<br><br>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..<br><br>&nbsp;When using the above methods you don't need to escape the quotation marks &quot; with a backslash ex. \&quot;. You&nbsp;&nbsp;can just put the html as-is between the two lines.<br><br>&nbsp;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.<br><br>&nbsp;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'}.<br><br>&nbsp;perlkid<br><br>
 
certainly javascript works from PERL....they are not really &quot;working together&quot;.&nbsp;&nbsp;I echo perlkid......you are simply using perl to write jscript.&nbsp;&nbsp;If the jscript is well formed it will work.&nbsp;&nbsp;You either have a jscript syntax problem or are trying a tedious (read error-prone) method to print it, as perlkid suggests.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top