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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Display (print) selected value
by SysApe9000 (Acolyte) on Oct 17, 2002 at 21:06 UTC
    Unfortunately your question seems a little vague. Are you using the CGI perl module? If you're not, you probably should be. The documentation for the CGI module goes into great detail about exactly what you are trying to accomplish. I'd start there.

    On UNIX-ish systems (including Linux) you can usually just type "perldoc CGI" at the command line and if your perl installation is complete and set up correctly you'll get the documentation your looking for.

    Good luck!

Re: Display (print) selected value
by sharkey (Scribe) on Oct 17, 2002 at 21:05 UTC
    You have to add "selected" to the appropriate option tag. Here is one way to do it:
    print " <form action=test.cgi method=post>\n"; print " <center><select name='selected' size=1>\n"; print " <option value='$item1'".($input{selected} eq $item1 ? " select +ed" : "")."> $item1</option>\n"; print " <option value='$item2'".($input{selected} eq $item2 ? " select +ed" : "")."> $item2</option>\n"; print " <option value='$item3'".($input{selected} eq $item3 ? " select +ed" : "")."> $item3</option>\n"; print " <option value='$item4'".($input{selected} eq $item4 ? " select +ed" : "")."> $item4</option>\n"; print " <option value='$item5'".($input{selected} eq $item5 ? " select +ed" : "")."> $item5</option>\n"; print " <INPUT type=submit name=submit value=Select\n"; print " </form><p><br>\n"; print " </select>\n";
      Allthough I would suggest to remove some redundancy in the code to make it a bit more readable:
      print qq|<form action="test.cgi" method="post">\n|, qq|<center><select name="selected" size="1">\n|; foreach ($item1, $item2, $item3, $item4, $item5) { my $selected_flag = $input{selected} eq $_ ? "selected" : ""; print qq|<option value="$_" $selected_flag> $_ </option>\n|; } print qq|<INPUT type="submit" name="submit" value="Select"\n|, qq|</form><p><br>\n|, qq|</select>\n|;
      Of course, I'd like also recommend to use the CGI module.

      Greetings,
      Janek

      This is looking good! However, I am still experiencing the same problem - or maybe I just don't know how to write the "print" statement so that the selected value displays onscreen when the "submit" button is pressed. How would you display the output when running this code - that is - showing what was selected by the user?

      Thanks again