Current location: Hot Scripts Forums » Programming Languages » Perl » popup menu: getting the user's selection


popup menu: getting the user's selection

Reply
  #1 (permalink)  
Old 09-24-04, 11:30 AM
jwh jwh is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
popup menu: getting the user's selection

I want to display a popup/drop-down to my users and get the value associated with that option chosen.

I have a working popup menu, but don't understand how to get the info I want.

When the user selects something from the menu, can I save the value that is associated with it? IE the site name is diplayed in the menu but I want to save the site URL when they make their selection.

the site_info array is in this format (I get this from another file, so I have to work with this format):
"Website name~http://www.websiteurl.com"

I break that apart into the array of just the names (@site_list), and the hash (%labels) of the name and url.

Code:
...

my $i=0;			
foreach my $site_info(@site_info) 
{
  	my ($site_name, $site_url)=split(/~http:\/\//,$site_info);
  	@site_list[$i]=$site_name;
  	$labels{$site_url}=$site_name;
  	$i++;
}
	
print $query->popup_menu(-name=>'which_site', -values=>\@site_list,-labels=>\%labels);
I am new to perl and am looking at "perl in a nutshell" but it doesn't help with this question. Any advice would be helpful.

Thanks, J
Reply With Quote
  #2 (permalink)  
Old 09-24-04, 01:57 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
This will give you the selected value:

Code:
my $url = $query->param('which_site');
after the user submits the form. Is that what you are looking for?

~Charlie
Reply With Quote
  #3 (permalink)  
Old 09-24-04, 02:14 PM
jwh jwh is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
my $url = $query->param('which_site');
Thanks, but not quite what I need.

This give me the site name from the popup; I want the URL that is associated with that site name.
Reply With Quote
  #4 (permalink)  
Old 09-24-04, 03:39 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
You'll have to keep a hash table of site names to URLs or use the url as the value in your drop down.

Code:
my %sites = (
  'my site name' => 'www.foo.com',
  'my other site name' => 'www.bar.com',
);

# The reference the url by site name:

my $site_name = $query->param('which_site');
my $url = $sites{$site_name};
You can probably split your @site_info into the hash and use that to generate your drop down:

Code:
my %sites = map {
  my ($name, $url) = split(/~http:/, $_);
  $name => "http:$url";
} @site_info;

print $query->popup_menu(-name=>'which_site', -values=> [ values %sites ], -labels=> \%sites);
~Charlie
Reply With Quote
  #5 (permalink)  
Old 09-27-04, 10:22 AM
jwh jwh is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
So using the hash in the popup labels really doesn't help me out?

I have the hash already so I will use the name value chosen from the popup to get the url. I just thought there was another way...

Thanks.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop down menu trouble NCC1701 PHP 10 11-12-04 04:09 AM
Simple tree menu w/ html and js? zcorpan JavaScript 2 06-18-04 06:17 PM
Popup menu isn't working Swytchcraft The Lounge 0 02-19-04 10:16 AM
popup select background dtm JavaScript 0 01-05-04 03:45 PM
putting content in a drop down menu tom PHP 7 07-04-03 02:25 PM


All times are GMT -5. The time now is 03:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.