zaphod1974
01-26-2006, 02:48 PM
I am new to Perl and even newer to HTML. I have my Perl code to display 2 drop down boxes on a HTML page without using forms. My question is how do I change my onchange lines to display the selections in the URL field in IE. I think I'm close with what I have.
Here is what I have:
package lab_report_header;
{
sub print_header
{
my($header_information)=@_;
my($dateToGet, $report_url, $report_name)=split("_B_", $header_information);
print<<"END_PRINT";
<table STYLE = "position: absolute; top: 65; left: 500;" border=0 width=200>
<tr>
<td>
END_PRINT
# connect to the database
$dbh = DBI->connect("dbi:RDB:ATTACH FILENAME meltdbdir:melt_rdb")
or die "Can't connect to Melt Shop database: $DBI::errstr\n";
if($dbh) {
my $startBlowEndTime="";
#statement handle - Setup SQL Statement to get list of dates available in DB
$sth = $dbh->prepare("SELECT DISTINCT(CAST(bv.start_tap_time AS DATE ANSI)),
EXTRACT(MONTH FROM bv.start_tap_time),
EXTRACT(DAY FROM bv.start_tap_time),
EXTRACT(YEAR FROM bv.start_tap_time)
FROM bof_vessel bv
ORDER by bv.start_tap_time DESC");
#Run it.
$sth->execute()
or die "Cannot execute statement in Lab Report Header $DBI::errstr\n";
print "<select onchange=\"if (this.options[this.selectedIndex].value) window.location.href=";
print "'", $report_url, "?dateToGet='+this.options[this.selectedIndex].value\" name=\"dateToGet\">\n";
while( @data = $sth->fetchrow_array()) {
my ($retrievedDate, $retrievedTime) = split(" ", $data[0]);
my $retrievedMonth=$data[1];
my $retrievedDay=$data[2];
my $retrievedYear=$data[3];
if( $retrievedMonth ne "" && $retrievedDay ne "" && $retrievedYear ne "" ) {
$retrievedDate = $retrievedYear . "-" . $retrievedMonth . "-" . $retrievedDay;
if( $dateToGet eq $retrievedDate ) {
print " <option selected value = \"", $retrievedYear, "-", $retrievedMonth, "-", $retrievedDay, "\">", $retrievedYear , "-", $retrievedMonth, "-", $retrievedDay, "</option>\n";
}
else {
print " <option value = \"", $retrievedYear, "-", $retrievedMonth, "-", $retrievedDay, "\">", $retrievedYear , "-", $retrievedMonth, "-", $retrievedDay, "</option>\n";
}
}
} # end of while
print "</select>\n";
} # end of if
#Must disconnect explicitly.
$dbh->disconnect or warn "Disconnection failed from Melt: $DBI::errstr\n";
print<<"END_PRINT";
</td>
<!--- changes to display a second option box 20051214/kjt--->
<!--- </tr> --->
<td>
END_PRINT
# second dropdown box definitions for lab test types
print "<select onchange=\"if (this.options[this.selectedIndex].value) window.location.href=";
print "'", $report_url, "?dateToGet=&TestTypeBox='+this.options[this.selectedIndex].value\" name=\"TestTypeBox\">\n";
if( $TestTypeBox eq "IB")
{
print " <option selected value = \"IB\">IB</option>\n";
}
else
{
print " <option value = \"IB\">IB</option>\n";
}
if( $TestTypeBox eq "P1")
{
print " <option selected value = \"P1\">P1</option>\n";
}
else
{
print " <option value = \"P1\">P1</option>\n";
}
if( $TestTypeBox eq "P2")
{
print " <option selected value = \"P2\">P2</option>\n";
}
else
{
print " <option value = \"P2\">P2</option>\n";
}
if( $TestTypeBox eq "P3")
{
print " <option selected value = \"P3\">P3</option>\n";
}
else
{
print " <option value = \"P3\">P3</option>\n";
}
if( $TestTypeBox eq "BD")
{
print " <option selected value = \"BD\">BD</option>\n";
}
else
{
print " <option value = \"BD\">BD</option>\n";
}
if( $TestTypeBox eq "DE1")
{
print " <option selected value = \"DE1\">DE1</option>\n";
}
else
{
print " <option value = \"DE1\">DE1</option>\n";
}
if( $TestTypeBox eq "DE2")
{
print " <option selected value = \"DE2\">DE2</option>\n";
}
else
{
print " <option value = \"DE2\">DE2</option>\n";
}
if( $TestTypeBox eq "ALT")
{
print " <option selected value = \"ALT\">ALT</option>\n";
}
else
{
print " <option value = \"ALT\">ALT</option>\n";
}
if( $TestTypeBox eq "BC")
{
print " <option selected value = \"BC\">BC</option>\n";
}
else
{
print " <option value = \"BC\">BC</option>\n";
}
if( $TestTypeBox eq "CO1")
{
print " <option selected value = \"CO1\">CO1</option>\n";
}
else
{
print " <option value = \"CO1\">CO1</option>\n";
}
if( $TestTypeBox eq "CO2")
{
print " <option selected value = \"CO2\">CO2</option>\n";
}
else
{
print " <option value = \"CO2\">CO2</option>\n";
}
if( $TestTypeBox eq "TDSLAG")
{
print " <option selected value = \"TDSLAG\">TDSLAG</option>\n";
}
else
{
print " <option value = \"TDSLAG\">TDSLAG</option>\n";
}
if( $TestTypeBox eq "C1")
{
print " <option selected value = \"C1\">C1</option>\n";
}
else
{
print " <option value = \"C1\">C1</option>\n";
}
if( $TestTypeBox eq "C2")
{
print " <option selected value = \"C2\">C2</option>\n";
}
else
{
print " <option value = \"C2\">C2</option>\n";
}
if( $TestTypeBox eq "C3")
{
print " <option selected value = \"C3\">C3</option>\n";
}
else
{
print " <option value = \"C3\">C3</option>\n";
}
print "</select>\n";
print<<"END_PRINT";
</td>
</tr>
<!-- end changes 20051214/kjt
</table>
END_PRINT
print<<"END_PRINT";
<table STYLE = "position: absolute; top: 65; left: 500;" border=0 width=200>
<tr>
<td>
END_PRINT
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
if( $dateToGet ne "" )
{
print "<H2 ID = \"shadowText\" STYLE = \"position: absolute; top: 10; left: 100; padding: 10; filter: shadow(direction = 225, color = black)\">". $report_name. $dateToGet ." </h2>\n";
}
else
{
$dateToGet = ($year + 1900)."-".($mon + 1)."-$mday";
print "<H2 ID = \"shadowText\" STYLE = \"position: absolute; top: 10; left: 100; padding: 10; filter: shadow(direction = 225, color = black)\">". $report_name. $dateToGet ." </h2>\n";
}
# build line for when report is generated
my $currDate = ($mon + 1)."-$mday-".($year + 1900);
if( $hour < 10 )
{
$currDate = $currDate . " 0$hour:";
}
else
{
$currDate = $currDate . " $hour:";
}
if( $min < 10 )
{
$currDate = $currDate . "0$min:";
}
else
{
$currDate = $currDate . "$min:";
}
if( $sec < 10 )
{
$currDate = $currDate . "0$sec";
}
else
{
$currDate = $currDate . "$sec";
}
print "<H3 STYLE = \"position: absolute; top: 60; left: 100; padding: 10\">Generated: $currDate </H3>\n";
return $dateToGet;
} # end of sub print_header
} # end of package lab_report_header
return 1; return 1
The first drop down displays dates retrieved from a database and the second displays test types.
Here is what I have:
package lab_report_header;
{
sub print_header
{
my($header_information)=@_;
my($dateToGet, $report_url, $report_name)=split("_B_", $header_information);
print<<"END_PRINT";
<table STYLE = "position: absolute; top: 65; left: 500;" border=0 width=200>
<tr>
<td>
END_PRINT
# connect to the database
$dbh = DBI->connect("dbi:RDB:ATTACH FILENAME meltdbdir:melt_rdb")
or die "Can't connect to Melt Shop database: $DBI::errstr\n";
if($dbh) {
my $startBlowEndTime="";
#statement handle - Setup SQL Statement to get list of dates available in DB
$sth = $dbh->prepare("SELECT DISTINCT(CAST(bv.start_tap_time AS DATE ANSI)),
EXTRACT(MONTH FROM bv.start_tap_time),
EXTRACT(DAY FROM bv.start_tap_time),
EXTRACT(YEAR FROM bv.start_tap_time)
FROM bof_vessel bv
ORDER by bv.start_tap_time DESC");
#Run it.
$sth->execute()
or die "Cannot execute statement in Lab Report Header $DBI::errstr\n";
print "<select onchange=\"if (this.options[this.selectedIndex].value) window.location.href=";
print "'", $report_url, "?dateToGet='+this.options[this.selectedIndex].value\" name=\"dateToGet\">\n";
while( @data = $sth->fetchrow_array()) {
my ($retrievedDate, $retrievedTime) = split(" ", $data[0]);
my $retrievedMonth=$data[1];
my $retrievedDay=$data[2];
my $retrievedYear=$data[3];
if( $retrievedMonth ne "" && $retrievedDay ne "" && $retrievedYear ne "" ) {
$retrievedDate = $retrievedYear . "-" . $retrievedMonth . "-" . $retrievedDay;
if( $dateToGet eq $retrievedDate ) {
print " <option selected value = \"", $retrievedYear, "-", $retrievedMonth, "-", $retrievedDay, "\">", $retrievedYear , "-", $retrievedMonth, "-", $retrievedDay, "</option>\n";
}
else {
print " <option value = \"", $retrievedYear, "-", $retrievedMonth, "-", $retrievedDay, "\">", $retrievedYear , "-", $retrievedMonth, "-", $retrievedDay, "</option>\n";
}
}
} # end of while
print "</select>\n";
} # end of if
#Must disconnect explicitly.
$dbh->disconnect or warn "Disconnection failed from Melt: $DBI::errstr\n";
print<<"END_PRINT";
</td>
<!--- changes to display a second option box 20051214/kjt--->
<!--- </tr> --->
<td>
END_PRINT
# second dropdown box definitions for lab test types
print "<select onchange=\"if (this.options[this.selectedIndex].value) window.location.href=";
print "'", $report_url, "?dateToGet=&TestTypeBox='+this.options[this.selectedIndex].value\" name=\"TestTypeBox\">\n";
if( $TestTypeBox eq "IB")
{
print " <option selected value = \"IB\">IB</option>\n";
}
else
{
print " <option value = \"IB\">IB</option>\n";
}
if( $TestTypeBox eq "P1")
{
print " <option selected value = \"P1\">P1</option>\n";
}
else
{
print " <option value = \"P1\">P1</option>\n";
}
if( $TestTypeBox eq "P2")
{
print " <option selected value = \"P2\">P2</option>\n";
}
else
{
print " <option value = \"P2\">P2</option>\n";
}
if( $TestTypeBox eq "P3")
{
print " <option selected value = \"P3\">P3</option>\n";
}
else
{
print " <option value = \"P3\">P3</option>\n";
}
if( $TestTypeBox eq "BD")
{
print " <option selected value = \"BD\">BD</option>\n";
}
else
{
print " <option value = \"BD\">BD</option>\n";
}
if( $TestTypeBox eq "DE1")
{
print " <option selected value = \"DE1\">DE1</option>\n";
}
else
{
print " <option value = \"DE1\">DE1</option>\n";
}
if( $TestTypeBox eq "DE2")
{
print " <option selected value = \"DE2\">DE2</option>\n";
}
else
{
print " <option value = \"DE2\">DE2</option>\n";
}
if( $TestTypeBox eq "ALT")
{
print " <option selected value = \"ALT\">ALT</option>\n";
}
else
{
print " <option value = \"ALT\">ALT</option>\n";
}
if( $TestTypeBox eq "BC")
{
print " <option selected value = \"BC\">BC</option>\n";
}
else
{
print " <option value = \"BC\">BC</option>\n";
}
if( $TestTypeBox eq "CO1")
{
print " <option selected value = \"CO1\">CO1</option>\n";
}
else
{
print " <option value = \"CO1\">CO1</option>\n";
}
if( $TestTypeBox eq "CO2")
{
print " <option selected value = \"CO2\">CO2</option>\n";
}
else
{
print " <option value = \"CO2\">CO2</option>\n";
}
if( $TestTypeBox eq "TDSLAG")
{
print " <option selected value = \"TDSLAG\">TDSLAG</option>\n";
}
else
{
print " <option value = \"TDSLAG\">TDSLAG</option>\n";
}
if( $TestTypeBox eq "C1")
{
print " <option selected value = \"C1\">C1</option>\n";
}
else
{
print " <option value = \"C1\">C1</option>\n";
}
if( $TestTypeBox eq "C2")
{
print " <option selected value = \"C2\">C2</option>\n";
}
else
{
print " <option value = \"C2\">C2</option>\n";
}
if( $TestTypeBox eq "C3")
{
print " <option selected value = \"C3\">C3</option>\n";
}
else
{
print " <option value = \"C3\">C3</option>\n";
}
print "</select>\n";
print<<"END_PRINT";
</td>
</tr>
<!-- end changes 20051214/kjt
</table>
END_PRINT
print<<"END_PRINT";
<table STYLE = "position: absolute; top: 65; left: 500;" border=0 width=200>
<tr>
<td>
END_PRINT
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
if( $dateToGet ne "" )
{
print "<H2 ID = \"shadowText\" STYLE = \"position: absolute; top: 10; left: 100; padding: 10; filter: shadow(direction = 225, color = black)\">". $report_name. $dateToGet ." </h2>\n";
}
else
{
$dateToGet = ($year + 1900)."-".($mon + 1)."-$mday";
print "<H2 ID = \"shadowText\" STYLE = \"position: absolute; top: 10; left: 100; padding: 10; filter: shadow(direction = 225, color = black)\">". $report_name. $dateToGet ." </h2>\n";
}
# build line for when report is generated
my $currDate = ($mon + 1)."-$mday-".($year + 1900);
if( $hour < 10 )
{
$currDate = $currDate . " 0$hour:";
}
else
{
$currDate = $currDate . " $hour:";
}
if( $min < 10 )
{
$currDate = $currDate . "0$min:";
}
else
{
$currDate = $currDate . "$min:";
}
if( $sec < 10 )
{
$currDate = $currDate . "0$sec";
}
else
{
$currDate = $currDate . "$sec";
}
print "<H3 STYLE = \"position: absolute; top: 60; left: 100; padding: 10\">Generated: $currDate </H3>\n";
return $dateToGet;
} # end of sub print_header
} # end of package lab_report_header
return 1; return 1
The first drop down displays dates retrieved from a database and the second displays test types.