in reply to How to store the value of a Javascript function as a Perl variable

Welcome coleb1115,

I am not an expert nor have I used Ajax, but I do use javascript with HTML to validate and populate form fields to be forwarded to Perl via cgi. I believe Ajax is used for continuous communication with a cgi program/script.

What you want can be done with javascript, by using the 'onClick' in the HTML. For example the following HTML will call a javascript subroutine called 'checkInfo' when the 'Login' button is clicked.

<INPUT type=submit value=Login name='ULogin' onClick="return checkInfo +();" />

The 'checkInfo' subroutine should set the fields in the Form for submission to the web server.

But, I think you could get what you wanted easier with just a drop down box with the info in table 1, that sends to your Perl script the single item selected, and then to generate a new response HTML document with the related contents of table 2 as another drop down box. (google 'select' for examples).

Whatever your solution, it will take some time before you understand the full picture, but once you understand the relationships, it will be fun to expand and innovate.

Good Luck...Ed

"Well done is better than well said." - Benjamin Franklin

  • Comment on Re: How to store the value of a Javascript function as a Perl variable
  • Download Code

Replies are listed 'Best First'.
Re^2: How to store the value of a Javascript function as a Perl variable
by locked_user sundialsvc4 (Abbot) on Jun 23, 2014 at 18:22 UTC

    FYI, Ed, “AJAX” simply is an ordinary HTTP transaction, but it is carried-out asynchronously through another connection with the host, with different Content-Type: and so on as appropriate.   It effectively implements a remote procedure-call (RPC) to the host, and every client-side JavaScript library in use today supports it.   On the host side, it is simply an HTTP POST/GET to a URL that is set-aside for this purpose.   On the client, the magic is done using closures, which must be provided both for normal and error responses from the host.   The customary data-transfer format, used for the actual body of the post, is ordinarily JSON or, less commonly, XML, but sometimes it is done just like ordinary form-data.

      HTML is a perfectly valid response, meaning the Content-Type is possibly the same as the page. Ajax can be done synchronously. DELETE and PUT and other methods are acceptable and becoming common because they are preferable and necessary for real REST. Closures are not a requirement. The data transfer is rarely JSON on the way up, where regular url-encoded params are usually used, but often so on the way back.

      A shallow summary with incorrect definitions and muddy use of terms like "RPC" ingrains misimpressions.

Re^2: How to store the value of a Javascript function as a Perl variable
by coleb1115 (Initiate) on Jun 23, 2014 at 18:14 UTC

    Using the drop down menu option, would I be able to put in my perl script that $groupName = the drop down list selection?

      Try this simple demo
      #!perl use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; # remove for prod my %groupname = ( ''=>'', 1=>'11111', 2=>'22222', 3=>'33333', 4=>'44444', ); my $q = new CGI; my $group = $q->param('group'); print $q->header,$q->start_html('test'); print qq! <form>Select Group <select name="group" onChange="submit()">!; for my $id (sort keys %groupname){ my $sel = ($id eq $group) ? 'SELECTED' : ''; print qq!<option value="$id" $sel>$groupname{$id}</option>!; } print q!</select></form><hr/>!; #Information Table if ($group){ print qq! <table border="1" cellpadding="10" cellspacing="0"> <h3> $groupname{$group} </h3> <tr> <td>Members of group: $group</td> <td>Jobs that group $group can do:</td> </tr> <tr> <td>Text on the way</td> <td>Text on the way</td> </tr> </table>!; } else { print "<h3>SELECT GROUP</h3>"; } print $q->end_html;
      poj