in reply to perl + cgi - onclick generation problem

How can I keep track of the set of text area fields already generated?

You could store the number of sets you already have on a certain page in a hidden field, and then always generate one more (n+1) ...

You only need Javascript to do this if you want to avoid the round trip to the server for every addition of a new set of text fields.

if ( $ENV{'QUERY_STRING'} =~ /^Button_name/ ) {

It's most likely easier to use a module such as CGI for extracting parameters, rather than matching stuff in QUERY_STRING yourself.  As a side effect, it would also provide features such as sticky form values, which might come in handy in this case (if the user has already entered stuff in the existing fields).

Replies are listed 'Best First'.
Re^2: perl + cgi - onclick generation problem
by matrixmadhan (Beadle) on Dec 11, 2008 at 07:09 UTC
    Thanks for the reply

    Sorry, am not clear with how to do that.
    I can retrieve the value in the hidden field using
    $cgi->param('hidden_field');
    But how to set the incremented value in the same hidden field ( this value indicates the number of set of textarea fields displayed )
    The only way I know to set a value for hidden_field is while creating, am not sure how to do the same without creating a new hidden_field for each time

    Any pointers?
      But how to set the incremented value in the same hidden field (...) The only way I know to set a value for hidden_field is while creating

      Well, you are creating the field anew for every page view, anyway (if we're talking about the non-javascript variant, that is), so just set the value as you did the first time...

      Or, in case you're using CGI for HTML generation, too (not just for parameter parsing), you can modify the (otherwise sticky) value with:

      $cgi->param('hidden_field', 'new value');
        I simply ran out of idea and cannot proceed further
        This is the code snippet what I had tried and it never works the way as expected
        sub hidden_field { my $counter = $cgi->param('field_1'); if ( not defined $counter ) { $counter = 1; } else { $counter++; } print $cgi->hidden('field_1', $counter); return $counter; } my $count = hidden_field; foreach ( 1 .. $count ) { #here is a seperate function that generates set of 3 text_area }
        Any pointers please?