Rainmaker has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have to load a combo box from database depending on what user selects from the other combo box. For this i need to call a perl function from the HTML code.This perl function will query database and load the other combo box with appropriate values. For eg:- Dept: <SELECT NAME=\"DeptName\" onChange=\" PERL-FUNCTION\">"; here onChange event calls the perl function,,,, but how to do this? Is there any other way to achieve this? any help wud be greatly appreciated,

Replies are listed 'Best First'.
Re: calling perl function from HTML
by nedals (Deacon) on Jul 18, 2005 at 23:26 UTC

    Based on your question, it sounds like you are hoping to ONLY populate a combo box based on a selection. It doesn't work like that. What you need to do is SUBMIT your form to the Perl script which will then re-write the HTML with the 'other' combo box populated.

    You can do this with an onchange event or, if javascript is disabled, provide a submit button.

Re: calling perl function from HTML
by jbrugger (Parson) on Jul 19, 2005 at 04:47 UTC
    Looks like you want some dynamic generated part of your page, this can be done using AJAX techniques (XMLHTTPRequest) like google suggest or google maps uses.
    there is a free and simple (also perl based) library to try for this, have a look at Sajax.

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: calling perl function from HTML
by Anonymous Monk on Jul 18, 2005 at 22:13 UTC

      Actually, what that search finds isn't useful.

      Most of the questions on this topic are how to embed perl in HTML, or other sorts of things that are done on the server side.

      Rainmaker's question is about telling the user agent to call a perl function when someone changes the value of an HTML form element.

      This can't be done reliably. onchange is typically used to call JavaScript (or JScript, LiveScript, ECMAScript, or whatever implementation it is that your browser uses)

      Yes, you can try specifying that the script's language is 'text/perl', or 'text/tcl' or 'text/vbscript', but you can't be sure that the browser will know what to do with it.

      If you want to try for yourself, save this code to file, and test it for yourself.