references:joomla.legacy:1.5:moshtml-makeoptionTable of Contents
makeOption
This method returns an object that can be passed in an array to another list handling method such as mosHTML::selectList. The method takes two arguments, one for the value of the option tag and optionally one for the text to display. If the text is omitted the single string is used for both the option value and the text. From Joomla! 1.0 onwards it is also optionally possible to override the default attribute names (’value’ and ‘text’). Syntaxobject makeOption ( string $value [, string $text [, string $value_name [, string $text_name ] ] ] )
The mosHTML::makeOption method returns a stdClass object with class variables ‘value’ and ‘text’. From Joomla! 1.0 onwards the class variable names actually used can be overridden as described above. ExamplesExample 1: Creating a list with hard coded values Example 1 // Option value and text will be the same. $mylist1 = array(); $mylist1[] = mosHTML::makeOption( 'Good' ); $mylist1[] = mosHTML::makeOption( 'Bad' ); $mylist1[] = mosHTML::makeOption( 'Ugly' ); // Option value and text will be different. $mylist2 = array(); $mylist2 = mosHTML::makeOption( '0', 'Select priority' ); $mylist2 = mosHTML::makeOption( '1', 'Low' ); $mylist2 = mosHTML::makeOption( '2', 'High' ); Example 2: creating a list from a Database query: Example 2 // alias the 'value' and 'text' fields and the array will // be in the correct format. $users = array(); $users[] = mosHTML::makeOption( '0', 'Select user' ); $database->setQuery( "SELECT id AS value, username AS text FROM #__users" ); $users = array_merge( $users, $database->loadObjectList() ); |



