I don't know how to explain this problem, so let's try with an example:

This minimal CGI script shows a page with two paragraphs and a small form that contains a dropdown menu, a textbox and two buttons. The textbox is for illustrative purposes only. After selecting a value from the dropdown menu and clicking the button "Set", the page reloads and the paragraphs show the new value selected, but the textbox stays with the same content (which I don't expect; I think it should change too). Similarly, clicking on "Add" changes the paragraphs but neither the textbox nor the dropdown menu reflect the new value.

In the real world, the dropdown menus are for selecting a date (the three typical year, month and day) and the "Add" button is "Go to the next day". I would like that the menus' default options turned into that of the next day (in order to be able to click more times) but, as shown, they stay the same.

I thought some kind of persistence of $q caused by mod_perl would be related but I just tried without it and the problem didn't go away.

#!/usr/bin/perl use warnings; use strict; use CGI; my $q = CGI->new; my $num = $q->param ('num') || 1; my $button = $q->param ('go'); ## increment $num if clicked in "Add" $num++ if (defined $button and 'Set' ne $button); print $q->header ('text/html'), $q->start_html, "paragraph 1: num is [$num]", $q->start_form, $q->popup_menu (-name => 'num', -values => [1 .. 3], -default +=> $num), $q->textfield (-name => 'foo', -value => "num is [$num]"), $q->submit (-name => 'go', -value => 'Set'), $q->submit (-name => 'go', -value => 'Add'), $q->end_form, "paragraph 2: num is [$num]", $q->end_html;

--
David Serrano


In reply to Form doesn't get updated after submission to same page by Hue-Bond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.