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

hello monks,
Is there a way to submit a form by just selecting something from a drop down menu?
Here is my code so far? What must ai cahnge?
@files = <../data/texts/*.txt>; foreach (@files) { $_ =~ s/.*[\/\\](.*)/$1/; } print start_form(-action=>"index.pl"); print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'}, 'Λόγ +ος Ψυχωφελής και Θαυμάσιος => ' ), popup_menu( -name=>'select', -values=> +\@files )), br(); print end_form(); $file = param('select') if param('select') or $file = $files[int(rand +(@files))]; open(IN, "<../data/texts/$file") or die $!; @data = <IN>; close(IN); $data = join("", @data); $data =~ s/\n/\\n/g;
How can i be able to submit the form without the use of a button just by waiting for the user t select soemthignfrom the drop-down menu? Thnaks

Replies are listed 'Best First'.
Re: Submit a form by just selecting something from a drop down menu
by jZed (Prior) on May 20, 2004 at 17:09 UTC
    If you really want to do this, Javascript is the way. But you might want to read some works on usability and human-computer-interaction, which are almost universally against self-acting pulldowns. Why? Because they make life difficult for anyone with physical spasms, poor eyesight, poor eye-hand coordination, or just a bad mouse. It's extra annoying when you open a pulldown just to look at what the options are and the next thing you know you are flying off to some URL you never meant to go to. Yes, clicking the "go" button is extra work, but, thanks, I like to make my browsing decisions myself rather than having the software make them for me.
Re: Submit a form by just selecting something from a drop down menu
by halley (Prior) on May 20, 2004 at 16:17 UTC
    I believe that all such examples are using JavaScript; the client runs the appropriate JavaScript actions when the user fiddles with the various widgets.

    --
    [ e d @ h a l l e y . c c ]

Re: Submit a form by just selecting something from a drop down menu
by Belgarion (Chaplain) on May 20, 2004 at 16:18 UTC

    I would imagine you would need to use the -onChange event handler as mentioned in the CGI documentation. Perl will not really help you in this case, since it's a client side situation. You will need to use some javascript code.

Re: (OT) Submit a form by just selecting something from a drop down menu
by Anonymous Monk on May 20, 2004 at 16:54 UTC
    First work out what your HTML output needs to look like - it should then be simple to produce this via your CGI script. The easiest way to acheive your desired result is to add an "onchange" event handler to the HTML select element so that the output looks more like:
    <select name="whatever" onchange="this.form.submit()">
    
    Note that it is best practice to provide a submit button as well, so that the form is fully functional for those users with JavaScript disabled. It is also preferable to keep event handlers out of your markup and assign them via a separate JavaScript layer, but I'll leave you to Google that one.
    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.