Something like this:
$checkBoxList[] = array('name'=>'Coffee','value'=>'Coffee','checked'=>'Y');
$checkBoxList[] = array('name'=>'Coffee Pot','value'=>'Coffee Pot','checked'=>'N');
$checkBoxList[] = array('name'=>'Tea Pot','value'=>'Tea Pot','checked'=>'Y');
draw_checkbox_menu($checkBoxList);
function draw_checkbox_menu($checkboxes,$parameters=false) {
foreach($checkboxes as $box) {
$field .= '<input type="checkbox" name="'.$box['name'].'" value="'.$box['value'].'"'.($box['checked']=='Y'?' CHECKED':'').'><br />';
}
return $field;
}
A one line function to display your checkboxes. Of course, you need extra code to accommodate your parameters. I have a similar function where the parameters are how many rows or columns to create for the checkboxes. So I could create a checkbox area with 3 columns and x rows or 4 rows and x columns just by passing a different parameter.
On Dec 7, 2004, at 3:10 PM, Mike wrote:
Hello,
I am having a hard time figuring this one out, maybe someone here (with fresh eyes) can offer a suggestion?
Here is the function...
// Draw Checkbox Menu
function draw_checkbox_menu($name, $values, $default = false, $parameters =
false) {
for ($i=0; $i<sizeof($values); $i++) { $field .= '<input type="checkbox" name="'.$name.'" value="' . $values[$i]['id'] . '"'; if(strstr($default, $values[$i]['id'])) { $field .= ' CHECKED'; } $field .= '> ' . $values[$i]['text'] . '<br> '; }
return $field; }
This function is passed the name of the checkbox list($name), the values
that are available($values = array) along with the ones that should be
checked ($default). Parameters too , but not important.
The problem is this. The Values are formatted like this...
value1|value2|value3...etc...
I use the strstr() function to check against the $default so I can check it
if so.
Well it works great..BUT, lets say the product has a category of "Coffee
Pots", but the one of the values available is "Coffee".
In this case both "Coffee" AND "Coffee Pots" get checked when only "Coffee
Pots" should.
What can I do to this function eliminate this?
Thanks
+--------------------------------------------+ Mike Yrabedra Mac@xxxxxxxx Your Mac Intelligence Resource +--------------------------------------------+ W: http://www.macagent.com/ E: agenty@xxxxxxxxxxxx
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php