Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

How to retain popup_menu selection between form submission

by ghosh123 (Monk)
on Jul 25, 2014 at 07:25 UTC ( #1095000=perlquestion: print w/replies, xml ) Need Help??

ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monk
I am working on a web application which looks like

Case I

Given a hostname provided in the text field if I press the
"Show jobs" button, it submits a form and loads the
same page with a popup_menu populated under the text
field and "Show jobs" button with all the jobs
running on that host.
Now I select a job in the popup_menu by a mouse click
on the values listed in the popup_menu. All fine so far.

Case II

Now to the right-hand side of this case -I gui objects, I
have another text field and "Show jobs" button. If I carry
out the same operation as I did in case-I on this
text-field and "Show jobs" at the right-hand side , it
submits the form and fetches one more popup_menu with
all the jobs running on this new host.
In addition to that the case-I text-field, submit button and popup_menu also appears on the reloaded page.
But the problem is the Case-I selection in the popup_menu is getting lost.

Please help me on how can I retain that Case-I selection as well when the page is submitted in Case-II and reloaded.
A sample code I am giving here below, the variables used in popup_menu are the usual array refs used in any such implementation and $qry is the cgi object.

<table border=0> <tr> <th bgcolor="#CCCCEE">First_Host</th><th>&nbsp;</th><th +bgcolor="#CCCCEE">Second_Host</th> </tr> <tr align=center> <td nowrap>@{[ $qry->textfield(-name=>'HOST_1') . '&nbsp; +' . $qry->submit(-name=>'HOST_1_LIST', -value=>'Show jobs') ]}</td> <td>&nbsp;</td> <td nowrap>@{[ $qry->textfield(-name=>'HOST_2') . '&nbsp; +' . $qry->submit(-name=>'HOST_2_LIST', -value=>'Show jobs...') ]}</td +> </tr> <tr align=center> <td bgcolor="#EEEEEE">@{[ $qry->popup_menu(-id=>'PM1', -n +ame=>'PM1_JOBS', -size=>10, -values=>$old_values, -labels=>$old_label +s, -multiple=>'false', -override=>'true', -onChange=>"fetchjobs(id,'' +,'','')") ]}</td> <td bgcolor="#EEEEEE">@{[ $qry->popup_menu(-id=>'PM2', -nam +e=>'PM2_JOBS', -size=>10, -values=>$new_values, -labels=>$new_labels, + -override=>'true', -onChange=>"fetchjobs(id,'','', '')") ]}</ +td> </tr> </table>

Replies are listed 'Best First'.
Re: How to retain popup_menu selection between form submission
by Anonymous Monk on Jul 25, 2014 at 07:35 UTC

    Please help me on how can I retain that Case-I selection as well when the page is submitted in Case-II and reloaded.

    Its simple, save the state somewhere,

    my $yo = LoadUserSession($user); ... if( $action == 'page-12-form1' ){ $yo->save_param( $query, [qw/ form1-ro form1-sham form1-bo /] ); } elsif( $action == 'page-12-form2' ){ $yo->save_param( $query, [qw/ form2-ro form2-sham form2-bo /] ); }

    Now the server knows about the user and what forms hes submitted, and you can request this information at any time

Re: How to retain popup_menu selection between form submission
by builat (Monk) on Jul 25, 2014 at 16:39 UTC
    It could be one more solution. Try to use Ajax tech. You can reload some elements of HTML DOM without rebooting all page && you have not send full form. If JS is not your Kung-Fu try CGI::Ajax -> MetaCpan link

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095000]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-05-16 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (62 votes). Check out past polls.

    Notices?