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


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

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS