On 09/23/2006 01:21 PM, RICHARD FERNANDEZ wrote:
Hi folks,
I'm trying to create an HTML form that will refresh itself based on user
input. In the POD for CGI it says that you can set the value of a named
parameter by using something like:
$query->param(-name=>'foo', -value=>'the value'); But it doesn't say (or at least I didn't see) anything about how to
redisplay the form with the new value in the textbox (or a different
textbox for that matter).
The sample script at the top of the doco (perldoc CGI) creates a blank
form that takes some input, a name, a "combination", and a color and
displays the user input in the bottom half of the page.
I would like to edit the value entered into the "name" textbox and
display my edited value in the same, or possibly a different textbox.
I've tried a bunch of things including the call to param() above,
without success.
For example, if the user types "Wilma" into the textbox, the script
should populate the target textbox with my edited value, say, "Betty".
As always, Thanks in Advance for any help! richf


Did you test it? It is my impression that CGI.pm works this way normally:

use strict;
use warnings;

my %nmap = (
    wilma => 'betty',
    fred => 'barney',
    bambam => 'pebbles',
);

  use CGI qw/:standard/;
  print
      header,
      start_html('Simple Script'),
      h1('Simple Script'),
      start_form,
      "What's your name? ",textfield('name'),p,
      "What's the combination?",
      checkbox_group(-name=>'words',
                     -values=>['eenie','meenie','minie','moe'],
                     -defaults=>['eenie','moe']),p,
      "What's your favorite color?",
      popup_menu(-name=>'color',
                 -values=>['red','green','blue','chartreuse']),p,
      submit,
      end_form,
      hr,"\n";

   if (param) {

        # Replace the parameter.
        my $temp = param('name');
        if ($nmap{$temp}) {
            # param('name',$nmap{$temp}); # This also works.
            param(-name => 'name', -value => $nmap{$temp});
        }

      print
          "Your name is ",em(param('name')),p,
          "The keywords are: ",em(join(", ",param('words'))),p,
          "Your favorite color is ",em(param('color')),".\n";
   }
   print end_html;




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to