0

I have an array in my Perl file that I'm using to populate a drop down menu in another PHP page.

So I have a perl.pl file that is called by ---> php.php. Now, this is the code in my PHP file

$output = shell_exec("/usr/bin/perl perl.pl $arg1 $arg2");
echo $output;

In my Perl file, this is what I pass at the end to get the drop-down menu:

    print "<SELECT id='process_type'>\n";
    foreach $value (@xvalues) { 
        #Removing any trailing white spaces from the option list
        $value_no_space =~ s/\s+//g;
         print "\t<OPTION value='$value_no_space'>$value</OPTION>\n";
         $i++;
    }
    print "</SELECT>\n";
    my $s = document.getElementById('process_type');
    print $s;
    print "\n";

I was hoping that when I selected an option from the menu on the PHP page, that variable would come back to and be stored in $s. However, this is not the case. I do understand that PHP is client side and Perl is server side, so thats why I'm unable to get the result back. Is there a work around? I really do need to have the selected option in the same Perl file in order to complete some other tasks I need to do ...

5
  • Do you mean JScript or JavaScript? Commented Nov 9, 2010 at 23:12
  • 3
    Troll detector is tingling... Commented Nov 9, 2010 at 23:25
  • Sorry, I meant Javascript. Changing title now ... Commented Nov 9, 2010 at 23:26
  • More of a Perl guy, here--but all the same--why are you sys-ing out to perl? Are you unaware of all the PHP utilities? Commented Nov 9, 2010 at 23:36
  • Probably not! But there is a graphing utility in Perl that I am using and I got my files to parse successfully after a lot of effort! The thought of doing it all over again in PHP scares me! Commented Nov 9, 2010 at 23:40

1 Answer 1

1

PHP is server side - I think you are confusing PHP with JavaScript.

To get it available serverside, give your select a name attribute.

For what reasons are you executing that portion of code with Perl via PHP system call?

I think what you want is best to handle all the HTML output and POST handling with PHP. Then you can use your Perl graphing utility after.

Sign up to request clarification or add additional context in comments.

3 Comments

Alex, in my Perl file : I changed my '<select id= ..>' to 'print "<SELECT name='process_type'>\n";' and also ' my $s = document.getElementById('process_type').value; print $s;' But I still can't get the value in the Perl file. Am I doing something incorrectly?
Hmm, well I actually have parsed some data in my Perl program. I want to execute this data based on some user input. So I'm passing that data to my PHP file, hoping that I can get the output of the drop-down list and continue my Perl program. Do you think there's a better way of doing this?
Hmm, the thing is. After I parse my file in Perl, I NEED user input to proceed with changing this data. So if I handled that in PHP. I would need to call my Perl script again and redo all the parsing, so that I can continue after collecting the user input. I think this is wasted resources since I'm parsing the same thing twice. Could you perhaps suggest why putting a 'name' attribute, doesn't allow me to gather the selected data?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.