You're here: Snippet Directory » PHP (128)
Language:

build_select_box_from_array ()

Language: English
Programming Language: PHP
Published by: bigdisk [not registered]
Last Update: 5/15/2006
Views: 1197


Description

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

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS