Hi,
Im working on a HTML drop down menu using a Global that loops through all the Categories and adds them into a Select menu with a <option selected> if this page matches the current category.
for example, the current category is: Foo / Blue
Category 1: <option value=/foo/">Foo</option>
Category 2: <option value=/foo/blue/" selected>Foo / Blue</option>
Category 3: <optionvalue=/foo/red/">Foo / Red</option>
The trouble im having is when i try and setup a string comparison Perl deosn't seem to be matching the strings correctly.
For example if $ThisDirectoryName = foo and $DirName = foo the following conditional work fine.
$output .= qq~\n<option value="/splash/$DirectoryName/" selected> $heading</option>~;
} else {
$output .= qq~\n<option value="/splash/$DirectoryName/"> $heading</option>~;
}
but when $ThisDirectoryName = foo/blue and $DirName = foo/blue the conditional returns true for all categories and adds a selected to each option.
Here's the full Global im using...
# genre_cetegories
my $Type = shift;
my $ThisDirectoryName = shift;
my $cat_db = $DB->table('Category') || return $GT::SQL::error;
$cat_db->select_options('ORDER BY Full_Name') || return $GT::SQL::error;
my $sth = $cat_db->select ({Type => $Type}, ['ID','DirectoryName','Full_Name']) || return $GT::SQL::error;
my $output=qq~<form style="margin:0;margin-left:10px;"><select name="genremenu" onchange="selectgenremenu(this.form);">~;
my $i=0;
while (my ($ID,$DirectoryName,$heading) = $sth->fetchrow_array) {
$i++;
my $DirName = $DirectoryName;
$DirName =~ s,/,,g;
$ThisDirectoryName =~ s,/,,g;
if ($ThisDirectoryName == $DirName) {
$output .= qq~\n<option value="/splash/$DirectoryName/" selected> $heading</option>~;
} else {
$output .= qq~\n<option value="/splash/$DirectoryName/"> $heading</option>~;
}
}
$output .= qq~</select></form>~;
return $output;
}
and how its called from Category.html <%genre_cetegories($Type,$DirectoryName)%>
Was thinking the forward slashes in the string ie. foo/blue may have been causing the error so i added a search and replace to remove them...
my $DirName = $DirectoryName;
$DirName =~ s,/,,g;
$ThisDirectoryName =~ s,/,,g;
With no luck.
Are there any error's you can see in this global?
thanks,
Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile
Im working on a HTML drop down menu using a Global that loops through all the Categories and adds them into a Select menu with a <option selected> if this page matches the current category.
for example, the current category is: Foo / Blue
Category 1: <option value=/foo/">Foo</option>
Category 2: <option value=/foo/blue/" selected>Foo / Blue</option>
Category 3: <optionvalue=/foo/red/">Foo / Red</option>
The trouble im having is when i try and setup a string comparison Perl deosn't seem to be matching the strings correctly.
For example if $ThisDirectoryName = foo and $DirName = foo the following conditional work fine.
Code:
if ($ThisDirectoryName == $DirName) { $output .= qq~\n<option value="/splash/$DirectoryName/" selected> $heading</option>~;
} else {
$output .= qq~\n<option value="/splash/$DirectoryName/"> $heading</option>~;
}
but when $ThisDirectoryName = foo/blue and $DirName = foo/blue the conditional returns true for all categories and adds a selected to each option.
Here's the full Global im using...
Code:
sub { # genre_cetegories
my $Type = shift;
my $ThisDirectoryName = shift;
my $cat_db = $DB->table('Category') || return $GT::SQL::error;
$cat_db->select_options('ORDER BY Full_Name') || return $GT::SQL::error;
my $sth = $cat_db->select ({Type => $Type}, ['ID','DirectoryName','Full_Name']) || return $GT::SQL::error;
my $output=qq~<form style="margin:0;margin-left:10px;"><select name="genremenu" onchange="selectgenremenu(this.form);">~;
my $i=0;
while (my ($ID,$DirectoryName,$heading) = $sth->fetchrow_array) {
$i++;
my $DirName = $DirectoryName;
$DirName =~ s,/,,g;
$ThisDirectoryName =~ s,/,,g;
if ($ThisDirectoryName == $DirName) {
$output .= qq~\n<option value="/splash/$DirectoryName/" selected> $heading</option>~;
} else {
$output .= qq~\n<option value="/splash/$DirectoryName/"> $heading</option>~;
}
}
$output .= qq~</select></form>~;
return $output;
}
and how its called from Category.html <%genre_cetegories($Type,$DirectoryName)%>
Was thinking the forward slashes in the string ie. foo/blue may have been causing the error so i added a search and replace to remove them...
my $DirName = $DirectoryName;
$DirName =~ s,/,,g;
$ThisDirectoryName =~ s,/,,g;
With no luck.
Are there any error's you can see in this global?
thanks,
Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile