[Javascript] Event handlers and Select Lists

Ron Wingfield rtwingfield at archaxis.net
Tue Jan 11 14:24:16 CST 2005


Hello List, first-timer here.

I've Googled around for info. on application menu systems, etc. Seems like a lot of sophisticated stuff out there. My approach is to dynamically load a drop-down (pop-up?) scrolling window from an applications table maintained in a MySQL database. -- Make a selection, and execute the associated executable object. Problem solved. 
I'm trying to use a mix of client-side JavaScript, and html, generated by Perl's CGI.  A state problem apparently requires a second click on the Execute Application (i.e., Submit) button. On the first pass, the same Applications Menu panel is re-displayed. Second click, the requested application page is executed. Interesting, too, that if you go back to the menu, select another ap., the thing returns to the previous ap. after which you can return to the menu, click submit, yet again, on the next ap., and the next ap's page will be executed. It's probably worth noting that regarding the design and functionality, the Submit button click could be eliminated and the desired application could be immediately executed "-onclick" from the popup menu (if possible, . . .should be?), because the user will only select one row (i.e., application to execute) from the list: 

I've tried to follow examples and suggestions from David Flanagan's book, JavaScript, The Definitive Guide, O'reilly and Associates, 4th. ed., 2002, but I just can seem to find the solution.  I guess I'm still not thinking through how the event-driven handlers on the client are interacting with the html that is generated by the server-side Perl code. 

Here is a sample of code that almost works. Notice that the -action argument is omitted; therefore, defaults(?) to the current document): 

Using the CGI to start the form: 

print   header(),
        start_html(-title=>$title, -bgcolor=>"cyan"),
        checkForm(),
        $cgi->start_form(
                -name=>"apps_menu",
                -method=>"GET",
                -onsubmit=>"return checkForm( this )"
);


. . .and a little farther down, notice that the "-onclick=>set_apx( )" apparently is not recognized by the popup_menu()function (subroutine, . . .whatever); however; executing immediately after the call produces the somewhat desirable results. I did try placing the call to set_apx() inside the checkForm() routine that is called -onsubmit, but that did not work (browser complains of undefined or nonexistent object; . . .perhaps a scope problem).
# ------------------------------
# Display Application Menu.
# ------------------------------
print
qq(<tr><td width=\"175\" align=\"right\">
          <b>Application: </b></td><td>),
$cgi-> popup_menu
(
        -name=>'ap_name',
        -values=>\@ap_names,
        -labels=>\%ap_labels,
        -size=>'8',
#       -onclick=>set_apx()   Not good!
); # BTW, . . .can't get anything like the following to compile w/o syntax errors
# -onclick=>document.apps_menu.action=apps_menu['ap_name'].value;);
set_apx(); # Sort-of works here (as I've described), but is outside of the popup_menu subroutine call. 
. . .and finally finish up the main with the usual suspects. 
print br(), submit(-name=>"action", 
-value=>"Start Application"), reset, end_form(), end_html(); 
$dbh->disconnect(); exit(0); 

Here is the "Set Application to Exec." subroutine that generates the JavaScript:URL that overrides the -action argument of the form tag generated by CGI.pm: # ----------------------------------------------------
sub set_apx { # Generate the JavaScript:URL here:
   print qq(<script><!--
      document.apps_menu.action=apps_menu['ap_name'].value;
   // --></script>);
}

 
This event-sensitive, client-side JavaScript is obviously 
executing the desired application, but like an old diesel tractor, . . .you have to double-clutch it. 
Suggestions?
Thanks & OTTF,Ron Wingfield
FreeBSD 4.8  --  Apache http 2.0.28 -- MySQL 
client/server 4.1.7Perl 5.8.5 -- p5-DBD-mysql-2.9004 driver -- p5-DBI-1.46 
--------------------------------------------------------------------------------


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050111/88eed15a/attachment.htm>


More information about the Javascript mailing list