Gossamer Forum
Home : Products : DBMan : Customization :

Jump to URL from Select field

Quote Reply
Jump to URL from Select field
How can i build a selectfield, that can do a jump to an URL.

I need a tag like this:

<SELECT NAME="GoMenu" ONCHANGE="jumpLink()" language="JavaScript"><OPTION SELECTED VALUE>Select a link<OPTION VALUE="$URLfromDB">$NAMEfromDB</SELECT></FORM><script language="JavaScript">function jumpLink(){ var a = document.jump.GoMenu.options[document.jump.GoMenu.selectedIndex].value +""; if(a != ''){ if(parent!=self){ var f = self; while(f!=window.top){ f = f.parent; } if(a.indexOf("://")!=-1){ f.body.window.location.href = a;}else{ window.top.location.href = a; } }else{ window.top.location.href = a; } document.jump.GoMenu.selectedIndex=0; } }</script>

I need a new Sub in my script like this:

sub build_quicklinks {
# --------------------------------------------------------
# Builds a SELECT field from URL with Go-Menu.

my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;

$name || ($name = $column);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

$output = qq|<SELECT NAME="GoMenu" ONCHANGE="QuicklinksLink()" language="JavaScript"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION value=$URL>$field");
}
$output .= "</SELECT>";

return $output;

}

Please give me the code for the mod.

Thank you very much

KAI

Quote Reply
Re: Jump to URL from Select field In reply to
It took me a little bit to figure out what you were doing, but I think I got it.

Code:

sub build_quicklinks {
# --------------------------------------------------------
# Builds a SELECT field from URL with Go-Menu.

my ($name_field, $url_field) = @_;
my (@fields, @lines, $line, $output,%options, $option, $found, $fieldnum1, $fieldnum2);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($name_field eq $db_cols[$i]) {
$fieldnum1 = $i; ++$found;
}
elsif ($url_field eq $db_cols[$i]) {
$fieldnum2 = $i; ++$found;
}
}
unless ($found == 2) {
return "error building quicklinks field: no fields specified!";
}

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
$options{$fields[$fieldnum1]} = $fields[$fieldnum2];
}
close DB;

$output = qq|<SELECT NAME="GoMenu" ONCHANGE="QuicklinksLink()" language="JavaScript">
<OPTION SELECTED>Select a link|;
foreach $option (sort keys %options) {
$output .= qq|<OPTION value="$options{$option}">$option|;
}
$output .= "</SELECT>";

return $output;
}
To use it --

print &build_quicklinks("NameField","URLField");


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Jump to URL from Select field In reply to
Thanks for your quick answer. It looks like an error in the script.

I us your script without changes and call your script with: print &build_quicklinks("Title","URL");

I get an Internal Server Error.

??? Any ideas?

Kai


Quote Reply
Re: Jump to URL from Select field In reply to
The syntax in the subroutine is correct according to my compiler.

Try taking out the line you use to call the subroutine (just to see what happens).

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Jump to URL from Select field In reply to
Ok,
if I delete the call, the error still occurs.
If I delete your script everything works fine.

Kai

Quote Reply
Re: Jump to URL from Select field In reply to
The only thing I can suggest is that you let me see your db.cgi file.

Copy it to a web-accessible directory (one where you would place .html files) and rename it to db_cgi.txt. Then come back here and let me know where it is. I'll see if I can find the problem.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Jump to URL from Select field In reply to
OK the url is http://www.exergy.de/test1/server.txt

Quote Reply
Re: Jump to URL from Select field In reply to
I don't know what to tell you. I copied your file and ran it through the compiler and it was just fine. No syntax errors.

It can't be in the running of the subroutine if the problem is still there when you take out the call to the subroutine. It would have to be within the syntax. But there are no syntax problems.

The only thing I can suggest is that you try uploading the file again.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Jump to URL from Select field In reply to
OK there was an error at the upload - sorry.

It work fine - thank you very much.

Kai