bighara has asked for the wisdom of the Perl Monks concerning the following question:
My script is creating a table in HTML based on a series of hashes read in from text files. The idea being that if the items in the table change, I just change the text file instead of the code. I am writing each table row by means of a foreach loop on an array list of the items. Here's a snippet:
foreach (@inventory) { print "<TR>"; print "<TD>$_</TD>"; print "<TD>$inv_prices{$_}</TD>"; print "<TD>$inv_weights{$_}</TD>"; print "<TD><input type=\"text\" size=\"4\" name=\"quantity$_\" ></ +TD></TR>" }
OK, my problem is with "quantity$_". That's the field that the user would actually change. When you enter a quantity into the field and press the SUBMIT button, the next script can't seem to recognize it as a parameter unique to a given item and prints nothing in the "shopping cart." Here's the code snippet from the 2nd script:
foreach (@inventory) { my $qty = param("quantity$_"); $qty{$_} = $qty } foreach (@inventory) { print "<TR>"; print "<TD>$_</TD>"; print "<TD>$inv_prices{$_}</TD>"; print "<TD>$qty{$_}</TD></TR>"; }
Nothing comes out on the page, though. If I leave out the code relevant to "quantity$_" and the %qty hash, then the rest formats fine.
How do I set up the parameter for the quantity field in the first script so that it changes for each item and get the 2nd script to read that parameter properly? Or am I just going about this in completely the wrong way? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI problem: trying to assign parameters in a loop
by chromatic (Archbishop) on Jan 19, 2002 at 22:48 UTC | |
|
Re: CGI problem: trying to assign parameters in a loop
by trs80 (Priest) on Jan 20, 2002 at 00:00 UTC | |
|
Re: CGI problem: trying to assign parameters in a loop
by bjelli (Pilgrim) on Jan 20, 2002 at 00:01 UTC | |
|
Re: CGI problem: trying to assign parameters in a loop
by nandeya (Monk) on Jan 20, 2002 at 03:51 UTC | |
|
Re: CGI problem: trying to assign parameters in a loop
by gav^ (Curate) on Jan 19, 2002 at 23:06 UTC | |
by Juerd (Abbot) on Jan 19, 2002 at 23:27 UTC | |
by gav^ (Curate) on Jan 20, 2002 at 00:04 UTC |