Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Because I cannot post my actual code I have ginned up a simplified example that demonstrates my intent.
Lets say I have a simple CGI script that generates HTML with a little javascript inline.
test.cgi
use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); local our $cgi = new CGI(); my @F_NAMES = ("a","b","c"); my @S_NAMES = (); print $cgi->header(); print qq( <script src='https://blah.blah.js'></script> <script type='text/javascript' language='javascript'> var xml; var xmlObject; var param; function do_Work() { var what = document.getElementsByName('FIRST_SELECTION')[0].v +alue; var test = document.getElementsByName('SECOND_SELECTION'); for(i = 0; i < chec.length; i++) { if(chec[i].checked == true) { type=chec[i].value; } } var build = document.getElementsByName('Build_ID')[0].value; alert(what+" "+test); xmlObject = loadXMLHttpObject(); alert(xmlObject); xmlObject.onreadystatechange = function(){ if(xmlObject.readyState == 4) { if(xmlObject.status == 200) { alert(xmlObject.responseText); //Some kind of assignment statement using document +.getElementsByName??? } } } xmlObject.open("POST", "https://blah_blah.blah2.cgi", true); param = "get_stuff&cmdnV="+what; xmlObject.send(param); } </script>); print $cgi->table({-border=>1, -cellpadding=>'1', -cellspacing=>'0', -width=>'100%', -bgcolor=>'whitesmoke'}), $cgi->Tr($cgi->td({-colspan=>3, -align=>'center'}, "<b>First Name(s):</b><br>", $cgi->scrolling_list( -name => 'FIRST_SELECTION', -values => [@F_NAMES], -size => 1, -default => 'none', -onChange=> 'do_Work();')), $cgi->Tr($cgi->td({-colspan=>3, -align=>'center'}, "<b>Second Name(s):</b><br>", $cgi->scrolling_list( -name => 'SECOND_SELECTION', -values => [@S_NAMES], -size => 5, -default => $S_NAMES[0]));
The javascript calls another cgi using some ajax, and according to the alert, returns the proper data.
I would like to assign that returned data to the scrolling_list with the name 'SECOND_SELECTION'; the theory being that for every element in @F_NAMES there is a number of unique entries for @S_NAMES and the user will need to populate the second scrolling_list with @S_NAMES. Is there a way to make such an update using the DOM and the javascript function do_Work()? Perhaps javascript and perl? I can not seem to find an ID for any of the DOM objects.
Thank you Kindly
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I fill a PERL scrolling_list with data returned from a javascript ajax call?
by Anonymous Monk on Apr 14, 2015 at 21:28 UTC |