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: 1251


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 11 echo ' 12 <SELECT NAME="'.$select_name.'">'; 13 14 $rows=count($vals); 15 16 for ($i=0; $i<$rows; $i++) { 17 echo ' 18 <OPTION VALUE="'.$i.'"'; 19 if ($i == $checked_val) { 20 echo ' SELECTED'; 21 } 22 echo '>'.$vals[$i].'</OPTION>'; 23 } 24 echo ' 25 </SELECT>'; 26 27 } 28

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS