|
|
Home Manual 11. API Reference mosHTML::selectList |
| mosHTML::selectList |
|
|
|
|
Last reviewed: Not reviewed mosHTML::selectListBuilds
an HTML <select> form field with <options> built from an
array of values. Both single item selects and multiple item
selects are supported. Syntaxstring selectList ( array &$options, string $tag_name, string $tag_attribs,string $key, string $text [, mixed $selected ] )
ExamplesExample 1: a single value select list: // The option tag with the value of zero is selected. $colours = array(); $colours[] = mosHTML::makeOption( '0', 'Red'); $colours[] = mosHTML::makeOption( '1', 'Green'); $colours[] = mosHTML::makeOption( '2', 'Blue'); $html = mosHTML::selectList( $colours, 'colour', 'size="1" class="inputbox"', 'value', 'text', 0 ); echo $html; which produces: <select name="colour" size="1" class="inputbox"> <option value="0" selected="selected">Red</option> <option value="1">Green</option> <option value="2">Blue</option> </select> which renders as: Example 2: a multiple value select list: // alias the 'value' and 'text' fields and the array will // be in the correct format. $users = array(); $users[] = mosHTML::makeOption( '0', 'No user' ); $database->setQuery( "SELECT id AS value, username AS text FROM #__users" ); $users = array_merge( $users, $database->loadObjectList() ); // Get selected users from a ficticious table. // We only need the 'value' to lookup the selected options. $database->setQuery( "SELECT id AS value FROM #__users_selected" ); $selected = $database->loadObjectList(); // Creates the HTML. // Note that 'multiple="true"' is required to make the HTML work properly. $html = mosHTML::selectList( $users, 'user_ids', 'size="10" class="inputbox" multiple="true"', 'value', 'text', $selected ); echo $html; which might produce: <select name="user_ids" size="10" class="inputbox" multiple="true"> <option value="0">No user</option> <option value="1">Bill Williams</option> <option value="2" selected="selected">Fred Bloggs</option> <option value="3">Amanda Fredericks</option> <option value="4" selected="selected">Natalie Sargos</option> </select> which renders as: Please report any errors on this page to the Developer Documentation Forum. |
|
| Last Updated ( Saturday, 03 September 2005 ) |
| < Prev | Next > |
|---|





