perl & javascript

They have: 6 posts

Joined: May 2000

Is it possible to use javascript within a perl script?

If it is possible, how do you go about doing it??

Thanks for any help.

They have: 5,633 posts

Joined: Jan 1970

Java Script is browser reliant. You can embed it into a Perl script, however it has to print to your browser before it can execute.

------------------
Adam
AIS Internet Solutions
[email protected]
www.aisinternet.com

[This message has been edited by adam (edited 10 May 2000).]

They have: 6 posts

Joined: May 2000

Thanks for your reply, but excuse me for appearing dumb (I'm completeley new to this - both perl & javascript), what do you mean by "printing before executing"?

Can you show me an example?

They have: 5,633 posts

Joined: Jan 1970

Not sure what the best example would be, but let’s say you’ve got a Perl script that prints a form box with dynamic content printed inside (for example the price of a product or what ever) you’ve also got a Java Script running in the PRINTED html that requires that only numbers can be entered into the text box.

Perl is server reliant and Java Script is client reliant. Which means Perl must be run from a server with Perl installed and Java Script must be run from a client (browser) with Java Script capabilities. You can mix the two together to their limitations (i.e. the Java Script HAS to be on the HTML page before it can run).

------------------
Adam
AIS Internet Solutions
[email protected]
www.aisinternet.com

They have: 850 posts

Joined: Jul 1999

here is another, very simple sample for using javascript inside your perl script:

code:

#!/usr/bin/perl
$var = <<"EOF";
<script language="javascript">
alert("WELCOME MY FRIEND");
</script>
EOF

print "Content-type:text/html\n\n";
print $var;
[/code]
$var will contain all of the javascript.  After you print out the http header, you just need to print the $var, and it will execute the javascript command.

You can see it in use at http://www.wiredstart.com/cgi-bin/alert.pl 

Hope that helps a little

------------------
http://www.wiredstart.com  : The Technology Start Page 

They have: 6 posts

Joined: May 2000

Thanks to everyone for all your help!!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.