Thursday, July 30, 2009

How to pass parameters from java script to Perl?

Javascript submits a form that prompts the user to enter data. In the form part, I am trying to call a perl script that should take the parameter values entered; document.form1.compName.value and document.form1.compPackage.value:


%26lt;FORM action="myPerl.pl" "-comp document.form1.compName.value -pkg document.form1.compPackage.value" Method=get name=form1 onsubmit= "return form1_onsubmit()" %26gt;





My Perl script gets called successfully but the parameters are not passed. I use


use Getopt::Std;


GetOptions( "comp=s",


"pkg=s",


);





getopts("f:");


if ($opt_comp) {


$comp = $opt_comp;


}


if ($opt_pkg) {


$package = $opt_pkg;


}





The perl script works fine from a command line:


myperl.pl -comp 'compname' -pkg 'pkgname'





any help?

How to pass parameters from java script to Perl?
Command line and CGI (Common Gateway Interface) are two separate things. You'll need to access your form parameters through the query string, which'll look like ?compName=xxx%26amp;compPackage=yyy. The thing you're trying to do in your form tag is invalid -- there can be no attribute-less values in XHTML/HTML. See second source for more information on forms.





$cgi_form = new CGI::Form;


$comp = $cgi_form-%26gt;param('compName');


$pkg = $cgi_form-%26gt;param('compPackage');





Have not tried this myself. You'll need to install and/or use the CGI stuff. See first source for more CGI-related information.

sim cards

No comments:

Post a Comment