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.
In reply to CGI problem: trying to assign parameters in a loop by bighara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |