Hi, Experts,
I have written a piece of perl/javascript codes listed below (a bit long, sorry. But it is portable to your local machine if you would like to do a test run):
By design, if you pick a cluster name, a list of corresponding case names are displayed. Then if you click 'reload' or hit 'F5' key, in IE, the cluster name backs to the default value 'Please Select a Cluster' and the case name list becomes blank. This is expected!
However, in Firefox, after you click reload, the cluster name STAYS the SAME as you selected before while the case name list becomes blank. This is WRONG!
How can I make it work in Firefox in the same way as in IE?
Many thanks for your kind advices.
I have written a piece of perl/javascript codes listed below (a bit long, sorry. But it is portable to your local machine if you would like to do a test run):
Code:
#!/usr/local/bin/perl
use strict;
use CGI qw/:all/;
local $| = 1;
my $title = "Test";
my $dilimiter = '__';
my $actionCode = 'myperl.pl';
my %clstIDName =
(
'0', '--Please Select a Cluster--',
'1', 'ClusterName1',
'2', 'ClusterName2',
'3', 'ClusterName3',
);
my %clstIDCaseIDName =
(
'1'=>{'11'=>'CaseName11', '12'=>'CaseName12', '13'=>'CaseName13'},
'2'=>{'21'=>'CaseName21', '22'=>'CaseName22', '13'=>'CaseName23'},
'3'=>{'31'=>'CaseName31', '32'=>'CaseName32', '13'=>'CaseName33'},
);
my $jscode = buildJSCode(\%clstIDName,\%clstIDCaseIDName,$dilimiter);
print header;
print
start_html(-title=>"$title", -script=>$jscode),
start_multipart_form(-action=>"$actionCode",
-name=>'theForm',
-onSubmit=>'return checkForCaseSelection(theForm.caseId);'),
table({-align=>'center'},
Tr(td({-align=>'right'}, 'Cluster: '),
td({-align=>'left'},
popup_menu(-name=>'clusterId',
-values=>[sort { $clstIDName{$a} cmp $clstIDName{$b} } keys %clstIDName],
-labels=>\%clstIDName,
-default=>'0',
-override=>1,
-onChange=>'showCaseListForCluster(theForm.clusterId, theForm.caseId);'))),
br(),
Tr(td({-align=>'right'}, 'Case: '),
td({-align=>'left'},
popup_menu(-name => 'caseId',
-values => []))),
br(),
Tr(td({-align=>'center',-colspan=>'2'}, (submit(-value=>'Upload'))))),
end_form(),
end_html;
exit 0;
sub buildJSCode {
my ($clstIDNameHashRef,$clstIDCaseIDNameHashRef,$dilimiter) = @_;
my $jscode = "var caseListByCluster = new Array();\n";
$jscode .= "var dlmter = '$dilimiter';\n";
foreach my $clID (keys(%{$clstIDNameHashRef})) {
if($clID > 0) {
my @caseIDArray4ThisCluster = keys(%{$clstIDCaseIDNameHashRef->{$clID}});
my @tmp;
foreach my $cID (keys(%{$clstIDCaseIDNameHashRef->{$clID}})) {
my $caseName = CGI::escape($clstIDCaseIDNameHashRef->{$clID}->{$cID});
push @tmp, "'$caseName$dilimiter$clID$dilimiter$cID'";
}
my $tmp = join ",", sort(@tmp);
$jscode .= "caseListByCluster[\"$clID\"] = new Array($tmp);\n";
} # end of if($clID > 0) {
} # end of foreach my $clID (keys(%{$clstIDNameHashRef})) {
$jscode .= "\n";
$jscode .= <<EO_JS;
function showCaseListForCluster(clusterIdObj, caseIdObj) {
if (clusterIdObj.selectedIndex > 0) {
var clusterID = clusterIdObj.value;
var thisArrLength = caseListByCluster[clusterID].length;
caseIdObj.disabled = false;
caseIdObj.options[0] = new Option('--Please Select a Case--', '0', true, true);
for(var i = 0; i < thisArrLength; i++) {
var j = i + 1;
var cNameClIdCId = caseListByCluster[clusterID][i];
var cNameClIdCIdArr = cNameClIdCId.split(dlmter);
var caseName = cNameClIdCIdArr[0];
var len = cNameClIdCIdArr.length;
var caseID = cNameClIdCIdArr[len-1];
caseIdObj.options[j] = new Option(unescape(caseName), caseID);
}
} // end of if (clusterIdObj.selectedIndex > 0) {
else {
caseIdObj.options.length = 0;
caseIdObj.disabled = true;
}
}
function checkForCaseSelection(caseSelBox) {
if (caseSelBox.disabled || caseSelBox.selectedIndex < 1) {
alert('You must select a case to proceed.');
return false;
}
return true;
}
EO_JS
return $jscode;
}
By design, if you pick a cluster name, a list of corresponding case names are displayed. Then if you click 'reload' or hit 'F5' key, in IE, the cluster name backs to the default value 'Please Select a Cluster' and the case name list becomes blank. This is expected!
However, in Firefox, after you click reload, the cluster name STAYS the SAME as you selected before while the case name list becomes blank. This is WRONG!
How can I make it work in Firefox in the same way as in IE?
Many thanks for your kind advices.