/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function createSelectMenu($menuName, $menuArray, $selectedID = '1') { $csmBuffer ="<select name=\"$menuName\" class=\"select-control\">\n"; for ($i = 0; $i < $arrayCount; $i++) { if ($selectedID == $menuArray[$i]->id) $csmBuffer .= '<option class="select-current" value="' . $menuArray[$i]->id . '" SELECTED>' . stripslashes($menuArray[$i]->name) . '</option>' . "\n"; else $csmBuffer .= '<option value="' . $menuArray[$i]->id . '">' . stripslashes($menuArray[$i]->name) . '</option>' . "\n"; } $csmBuffer .= "</select>\n"; return $csmBuffer; } $item1->id = 0; $item1->name = 'Item 1'; $item2->id = 1; $item2->name = 'Item 2'; $item3->id = 2; $item3->name = 'Item 3'; $menuArray[0] = $item1; $menuArray[1] = $item2; $menuArray[2] = $item3; $menu = CreateSelectMenu('menu', $menuArray, 1); // Select second item for example echo $menu;
URL: http://code.cshaiku.com/code_php_create_select_menu.php