CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Drop DownMenu-option selected

 



cathy
newbie

Sep 29, 2000, 8:38 AM

Post #1 of 6 (1293 views)
Drop DownMenu-option selected Can't Post

On a web page, I display a drop-dwon menu where the user can select one name from a list of names. I save the selected name to a file. When the user goes back to view the list (there are other fields, of course), I would like to again display ALL the names in the list but have the name they previously selected show up as selected with the other names available for selection (the list of names are in a flat file). This can be done using ASP, so it seems it should be possible in cgi. In ASP, the code is something like: <option> </option><option <% If rs("QuarterRelease")= "" Then %>selected<% End if %>></option>
I tried adapting this into cgi, but it didn't seem to work. Any suggestions/examples?


dws
Deleted

Sep 28, 2000, 10:58 PM

Post #2 of 6 (1293 views)
Re: Drop DownMenu-option selected [In reply to] Can't Post

"It didn't seem to work" covers a lot of ground. Show us your code, and tell us what you observed.


cathy
newbie

Sep 29, 2000, 11:20 AM

Post #3 of 6 (1293 views)
Re: Drop DownMenu-option selected [In reply to] Can't Post

"it didn't work" means it didn't perform as I had hoped it would--display the full list but have the previously selected item highlighted.

Unfortunately I deleted the code that did not perform as desired, but I can try to reconstruct it.


cathy
newbie

Sep 29, 2000, 11:38 AM

Post #4 of 6 (1293 views)
Re: Drop DownMenu-option selected [In reply to] Can't Post

Here's the code:
print "<form method=$POST action=$action>";
open(RESOURCES, "</usr/local/httpd/cgi-bin/admin/resources.txt")&#0124; &#0124;&ErrorMessage;
@people=<RESOURCES>;
close(RESOURCES);
$totalresources = @people;
$resourceindex=0;
$size="10";
$name="Resource";
print "<tr><td><select size=$size name=$name>";
print "<option> </option>";
while ($totalresources > 0){
print "<option if ($people[$resourceindex] =~m/$lines[$record+3]/){selected}</op
tion>";
--$totalresources;
++$resourceindex;
}

When I execute the file, the drop-down menu displays but there are no items in the menu.


dws
Deleted

Sep 29, 2000, 2:12 PM

Post #5 of 6 (1293 views)
Re: Drop DownMenu-option selected [In reply to] Can't Post

I suggest laying out the HTML first, then working backwards to get the Perl you need.

You'll end up with something like this
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$selected = $lines[$record + 3]; # i assume this is the person previously selected
...
print "<select name=$name size=$size>\n";
print "<option> </option>\n";
foreach my $person ( @persons ) {
print "<option value=\"$person\"";
print " selected" if $person eq $selected;
print ">$person</option>\n";
}
print "</select>\n";</pre><HR></BLOCKQUOTE>


[This message has been edited by dws (edited 09-29-2000).]


cathy
newbie

Sep 29, 2000, 4:02 PM

Post #6 of 6 (1293 views)
Re: Drop DownMenu-option selected [In reply to] Can't Post

It works! Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives