in reply to (cLive ;-)Re: nesting foreach statements
in thread nesting foreach statements
2) When user fill out form, they can choose multiple options. After they submit, it saves the options into a flat text file, along with the other form's answer: userid|password|name|email|Blue,Red|comments 3) The user has the option to come back in later time and edit his info. It is prompted with an edit form on which his previous answers are already inserted. In this case I would need the edit form to present the "colors" field in this way:<select name="colors" multiple size=5 "> <option>Blue <option>Red <option>Yellow <option>Green </select>
I am limited with perl and I have tried to basically read the array from the choice of colors: @colors = ("Blue","Red","Yellow","Green"); make the chosen colors scalar into an array and read it: @chosen = ("Blue","Red"); an then tried to compare both but all I can come up with is a bunch of nested foreach statements which is not good:<select name="colors" multiple size=5 "> <option selected>Blue <option selected>Red <option>Yellow <option>Green </select>
Anyway, you can tell that I am not starting well with my thinking. Help! Thank you.foreach colors { foreach chosen { if $chosen eq $color { $editchosen = <option selected>$color } else { $editchosen = <option>$color } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(cLive ;-)Re: nesting foreach statements
by cLive ;-) (Prior) on Apr 07, 2002 at 04:38 UTC |