Du bist hier: Snippet-Verzeichnis » PHP (128)
Sprache:

build_select_box_from_array ()

Sprache: English
Programmiersprache: PHP
Veröffentlicht von: bigdisk [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1177


Beschreibung

Takes PHP arrays and builds a pop-up HTML box from it. You can optionally pass in a value to tell it with item is SELECTED by default.Originally published on http://www.phpbuilder.com/

Code

1 function build_select_box_from_array ($vals,$select_name,$checked_val="xzxz") { 2 /* 3 Takes one array, with the first array being the "id" or value 4 and the array being the text you want displayed 5 6 The second parameter is the name you want assigned to this form element 7 8 The third parameter is optional. Pass the value of the item that should be checked 9 */ 10 echo "<SELECT NAME=$select_name>\n"; 11 $rows=count($vals); 12 13 for ($i=0; $i<$rows; $i++) { 14 echo " <OPTION VALUE=$i".($i==$checked_val ? "SELECTED>" : ">").$vals[$i]."</OPTION>\n"; 15 } // for each row 16 echo "</SELECT>\n"; 17 18 } // function build_select_box_from_array

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS