Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating pulldown menus using the stored $variables 1

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
I have 3 pulldown menus that represent a date.
ie: month day year

When the HTML page opens I want the selected values to match what I have stored in a .pm file.
ie:
$stored_year = "2002";
$stored_month = "January";
$stored_month_date = "1";


How do I dynamically write code in a .cgi file for the pulldown menus using the $variables stored.

Thanks, Cal In the begining
Let us first assume that there was nothing to begin with.
 
in the tag, i think all you have to do is put:[tt]
VALUE=...[/tt]

and have the '...' be the value of your stored variable. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
This is an example:
$storedvalue <- one of your stored values
@list <- list of values in your select box

my $selectbox = qq|<SELECT NAME=&quot;<somename>&quot;>|;
foreach (@list)
{
if $_ eq $storedvalue
{
$selectbox .= &quot;<OPTION SELECTED>$_</OPTION>&quot;;
next;
}
$selectbox .= &quot;<OPTION>$_</OPTION>&quot;;
}
$selectbox .= &quot;</SELECT>&quot;;

I also add formating marks when I do something like this so it matches the html but you don't have to.
 

syntax error at Untitled line 38, near &quot;if $_ &quot;
syntax error at Untitled line 39, near &quot;;}&quot;

shift(@names);
my $selectbox = qq|<SELECT NAME=&quot;<memberesub1>&quot;>|;
[red]syntax error [/red]foreach (@names)
{if $_ eq $stored_month{$selectbox .= &quot;<OPTION SELECTED>$_</OPTION>&quot;;next [red]syntax error [/red];}
$selectbox .= &quot;<OPTION>$_</OPTION>&quot;;}
$selectbox .= &quot;</SELECT>&quot;;
} In the begining
Let us first assume that there was nothing to begin with.
 
Sorry I didn't test the code.

### start code ###
shift(@names);
my $selectbox = qq|<SELECT NAME=&quot;<memberesub1>&quot;>|;
foreach (@names)
{
if ( $_ eq $stored_month ) <- add parenthesis
{
$selectbox .= &quot;<OPTION SELECTED>$_</OPTION>&quot;;
next;
}
$selectbox .= &quot;<OPTION>$_</OPTION>&quot;;
}
$selectbox .= &quot;</SELECT>&quot;;
} <- Get rid of this curly bracket unless its part of a function

Also the less than and greater than symbols were just pointing out where to place something you don't have to put them around <memberesub1>.
 
Very Greatful to everyone for your help.


What is qq?

Thanks, Cal In the begining
Let us first assume that there was nothing to begin with.
 
its an alternative to double quotes.
You can use qq and some symbol (Any characters except white space and alpanumerics) the O'Reilly 'Programming Perl' book uses slashes (/) to represent double quotes. I tend to use pipes (|). That way if you have double quotes in your string you don't have to escape them. There is also a single q// you can use to represent single quotes.

examples:
$test = &quot;this is a string&quot;;

equivalents:
$test = qq/this is a string/;
$test = qq|this is a string|;
$test = qq%this is a string%;
etc....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top