Re: checkboxes and selection lists
| From: | John Nichel | Date: | Tue, 05 Nov 2002 06:16:47 +0000 |
| Subject: | Re: checkboxes and selection lists | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122731@lists.php.net to get a copy of this message | ||
For something like this, instead of doing all the HTML, I would set up and array, and then loop through the array to output the HTML...
<SELECT CLASS="select" NAME="qual">
<?php
for ( $i = 0; $qual_array[$i]; $i++ ) {
if ( $_POST['qual'] == $qual_array[$i] ) {
echo ( "<OPTION VALUE=\"" . $qual_array[$i] . "\" SELECTED>" . $qual_array[$i] . "</OPTION>\n" );
} else {
echo ( "<OPTION VALUE=\"" . $qual_array[$i] . "\">" . $qual_array[$i] . "</OPTION>\n" );
}
}
?>
</SELECT>
marco_bleeker@hetnet.nl wrote:
Hi, as a beginner I find the way you declare variables through HTML-forms quite straightforward. But the reverse, to put the same variables back into a form field is not so obvious for selection lists and checkboxes. Would for instance this be the best way: <SELECT CLASS="select" NAME="qual"> <OPTION VALUE="A" <?=if($qual=='A'){return 'SELECTED'}?>>A</OPTION> <OPTION VALUE="B" <?=if($qual=='B'){return 'SELECTED'}?>>B</OPTION> <OPTION VALUE="C" <?=if($qual=='C'){return 'SELECTED'}?>>C</OPTION> </SELECT> or would there be something more elegant? Thanks, Marco -------------------------------------------------------------------------------- Internet wordt pas leuk als je mee kunt doen. Ga naar http://www.hetnet.nl