Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm quite new to perl, and my question is this: I have a perl script I need to execute at the push of a button. I also have to run a few lines of javascript at the same button push, so how can I run both? I tried "document.write(garbage about executing a script)" but with no results. Any help is much appreciated, and sorry to bother you all with what is really a javascript question, but I'm not really sure where else to turn... thanks, jaraph

Replies are listed 'Best First'.
Re: Execute Perl from Javascript
by jlongino (Parson) on Aug 03, 2001 at 06:04 UTC
    jaraph

    Here is a snippet that I cut and pasted from a program I wrote. I hope it is complete enough to at least give you an idea. I'm sure that there are many other ways to do it. Just be sure that the directory that the perl script is located in is authorized to run cgi programs. The server cgi-bin directory normally has that ability.

    <html> <head> <script language="JavaScript" type="text/javascript"> function CheckKey (form) { var CGI_URL = "http://my.whatever.site/cgi-bin/" // do javascript stuff here form.action = CGI_URL + "idlookup.pl"; form.submit() // executes idlookup.pl on server return true } </script> </head> <body> <form name=identify method=POST action='javascript:return CheckKey(doc +ument.forms[0]) onsubmit="javascript:return CheckKey(document.forms[0])"> <INPUT TYPE="button" NAME="Checkit" VALUE=' Submit ' onclick="javascript:return CheckKey(document.forms[0])"> </form> </body> </html>
    Hope this helps.
Re: Execute Perl from Javascript
by tachyon (Chancellor) on Aug 03, 2001 at 15:05 UTC

    Here is a very simple example. In a form you can have javascript handlers execute onSubmit as shown. Your form can be no more than a single button.

    <html> <head> <script language="JavaScript"> function CheckForm (form) { // do javascript stuff here // return true to submit form // retrun false and form will not submit return true } </script> </head> <body> <form name="form" method="POST" onSubmit="CheckForm" action="/cgi/mail +list.cgi"> <input type="text" name="message" value="Just Another Hacker"> <input type="submit" name="submit" value="Hello Javascript"> </form> </body> </html>

    This is the sort of structure you use a lot for client side form validation. If you return false the form is not submitted to the cgi script.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print