This my code which have problem

P

phal

Hi all

The below code has problem when I want to double click or backward or
forward several time the hidden field record the duplication
information, and this is not what I want, and when the duplicate
information is too much, it getting slower and slower then sometime
hang the PC as well.

I do not use Cookie for storage.

Thank
Phal

----------------------------------------------------------


if(param('START_'))
{
$print_question=TR(th(submit(-name=>'GOTO',-value=>'Next'),
hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$select_display),
hidden(-name=>'POP',-value=>$popup_question),
popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>1),
submit(-name=>'GOTO',-value=>'Go')));
$print_question.=&Generate_Question(\@{$questions{1}},\@ALL_QUESTIONS,\1,\'None
~') ;
if(scalar (@{$questions{1}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>1),submit(-name=>'GOTO',-value=>'Go')));
}
&Display_Question($print_question);
}
#----------------------------------------------------------
$popup_question=param('POP');
my @popup_;

for(my $n=1; $n<= $popup_question; $n++){
push @popup_,$n;
push @popup_, 'Submit' if $n == $popup_question;
}
my $total_display=param('TOTAL_DISPLAY');
my $total_x=($per_display*$total_display)+$less_question ;

my %question_answers;
my $print_hidden;
#----------------------------------------------------------
for(my $x=1; $x<=$total; $x++)
{
my $count_q=$x.'Q';
my $question_id=param($count_q); # get the question ID
my $question_answer;
my $question_type;

my $check_box=$question_id.'CHECK';
my $radio_box=$question_id.'RADIO';


if(param($check_box))
{
foreach(param($check_box)){
$question_answer.=$_;
}

$question_type=$check_box;
}
else{
$question_answer=param($radio_box);
$question_type=$radio_box;
}

if($question_answer ne "")
{
print
hidden(-name=>$count_q,-value=>$question_id),hidden(-name=>$question_type,-value=>$question_answer);

}

}
#-----------------------------------------------------------
for( my $xp=0; $xp < @popup_; $xp++)
{
if(param('GOTOQ') eq "$popup_[$xp]")
{
my $select=param('TOTAL_DISPLAY'); # total question to display in
each screen
my $count=0; # count the questions
$count=1 if($popup_[$xp] =~/1/); # when the first question count
start from 0
$count=1+$select*$popup_[$xp]-$select if($popup_[$xp] > 1); # when
not the first question count

$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),
hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$select_display),hidden(-name=>'POP',-value=>$popup_question),
hidden(-name=>'CURRENT',-value=>$popup_[$xp]),
popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>$popup_[$xp]),
submit(-name=>$popup_[$xp],-value=>'Go')));
$print_question.=&Generate_Question(\@{$questions{$popup_[$xp]}},\@ALL_QUESTIONS,\$count,\'None
~ ') ;
if(scalar (@{$questions{$popup_[$xp]}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>$popup_[$xp]),submit(-name=>'GOTO',-value=>'Go')))
; }
&Display_Question($print_question);
}
}
#-------------------------------------------------------------
if(param('GOTO') eq 'Nextxx')
{

my $current=param('CURRENT');
my $select_display=param('TOTAL_DISPLAY'); # total question to display
in each screen
my $examid=param('ID');
$popup_question=param('POP');

$current+=1;
print "$current $popup_question";

if($current < $popup_question)
{
my $count=0; # count the questions
$count=1 if($current =~/1/); # when the first question count start
from 0
$count=1+$select_display*$current-$select_display if($current >
1); # when not the first question count

$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),
hidden(-name=>'ID',-value=>$examid),hidden(-name=>'TOTAL_DISPLAY',-value=>$select_display),hidden(-name=>'POP',-value=>$popup_question),
hidden(-name=>'CURRENT',-value=>$count),
popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],
-default=>$count),
submit(-name=>$count,-value=>'Go')));
$print_question.=&Generate_Question(\@{$questions{$count}},\@ALL_QUESTIONS,\$count,\'None
~ ') ;
if(scalar (@{$questions{$current}}) > 4) {
$print_question.=TR(th(submit(-name=>'GOTO',-value=>'Next'),popup_menu(-name=>'GOTOQ',-value=>[1..$popup_question,'Submit'],-default=>$current),submit(-name=>'GOTO',-value=>'Go')))
; }
&Display_Question($print_question);
}
}
#-------------------------------------------------------------

if(param('GOTOQ') eq 'Submit')
{
my (%temp,@data,$question_id,$count_q,$question_answer);
#----------------------------------------------------------------------------------
for(my $x=1; $x<=$total; $x++)
{
$count_q=$x.'Q';
$question_id=param($count_q); # get the question ID
$question_answer='RtExt';

my $check_box=$question_id.'CHECK';
my $radio_box=$question_id.'RADIO';

if(param($check_box))
{
foreach(param($check_box)){$question_answer.=$_.' MIXX ';}
}
else
{
$question_answer=param($radio_box);
}

print "$question_id=$question_answer <br>";
}
}

print end_form(),end_html();
##############################################################################
sub Generate_Question
{
my ($total_)=shift(@_);
my ($aoh)=shift(@_);
my ($tcount)=shift(@_);
my ($value_)=shift(@_);

my @total=@$total_;
my @AOH=@$aoh;
my $count=$$tcount;
my $value=$$value_;

my $print_question;
my %label_hash;
my $label_count=1;


foreach my $hash(@AOH)
{
for my $k (@total)
{
if($k)
{ foreach my $_ik(sort keys %{$hash->{$k}})
{
if($_ik eq 'a_question'){

$print_question.=TR(th(hidden(-name=>$count.'Q',-value=>$k)));

$print_question.=TR(th({-align=>'left',-colspan=>2},font({-size=>$_EQ_body},$count,
". ",$hash->{$k}{$_ik})));
$count+=1;
}
if($_ik eq 'b_description'){
$print_question.=TR(th({-align=>'left'},font({-size=>$_EQ_body},"(",$hash->{$k}{$_ik},")")));
}
if($_ik eq 'c_answer') {
$label_count=1;
for my $in(0..$#{$hash->{$k}{$_ik}})
{ # print " IN SIDE $label_count ";
$label_hash{$label_count}=$hash->{$k}{$_ik}[$in];
$label_count++;

}
# print "NUMBER $label_count";
my @size=keys %label_hash;
# print "dddddddddddd @size dddddddddd";

$print_question.=TR(th({-align=>'left'}, font({-size=>$_EQ_body},
checkbox_group(-name=>$k.'CHECK',-values=>[1..$#size+1],-linebreak=>'true',-labels=>\%label_hash,-default=>$value),hidden(-name=>$k.'TYPE',-value=>'CHECK_GROUP'))))
if ($hash->{$k}{'1_question_type'} =~/check_group/gi);
$print_question.=TR(th({-align=>'left'}, font({-size=>$_EQ_body},
radio_group(-name=>$k.'RADIO',-values=>[1..$#size+1],-linebreak=>'true',,-labels=>\%label_hash,-default=>$value),hidden(-name=>$k.'TYPE',-value=>'RADIO_GROUP'))))
if ( $hash->{$k}{'1_question_type'} =~/radio_group/gi);
}
}
}

}

}
return $print_question;
}

--------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top