Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
"be consistent"
 
PerlMonks  

Submit a form by just selecting something from a drop down menu

by Nik (Initiate)
on May 20, 2004 at 12:14 UTC ( [id://354992]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 halley (Prior) on May 20, 2004 at 12: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 12: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 12: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.
      actually i myself usecgi.pm and dotn want to use js so i must add a button. ok i did put a button but the problem now is that it doesn remain to the same row when i print it.
      print start_form(-action=>"index.pl"); print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'}, 'Ëà +¼Ã£Ã¯Ã² Øõ÷ùöåëÞò êáé ÈáõìÜóéïò => ' ), popup_menu( -name=>'select', -values=> +\@files )), submit('ok'); print end_form(); <code> Ho can i make it stay just after (just right to the drop-down menu?) and also i renamed my text files from *.txt to just ther filenames without the +extenesions. but then i noticed that open wont opne them why? <code> @files = <../data/texts/*>; foreach (@files) { $_ =~ s/.*[\/\\](.*)/$1/; } open(IN, "<../data/texts/$file") or die $!; @data = <IN>; close(IN);
      if i make them *.txt again open can open them but if i remove the .txt extension. it cant, why?
        For the first part you didn't put the submit() inside the p() so its below that paragraph. I don't know what your second issue is. Does it die with an error explaining what happened?

        ___________
        Eric Hodges
      Yes the html output needs to be like this but the problem is how can i implement this code with the use of cgi.pm?
      Yes the html output needs to be like this but the problem is how can i implement this code with the use of cgi.pm?
Re: Submit a form by just selecting something from a drop down menu
by jZed (Prior) on May 20, 2004 at 13: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://354992]
Approved by diotalevi
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.