Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 10 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Manual arrow 11. API Reference arrow mosHTML::makeOption

mosHTML::makeOption PDF Print E-mail

Last reviewed: Not reviewed
phpDocumentor

mosHTML::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').

Syntax

object makeOption ( string $value [, string $text [, string $value_name [, string $text_name ] ] ] )

$value
is the value that will be used for the HTML tag.
$text
is the text to be displayed in the HTML tag. This parameter is optional and if omitted the text displayed will be the same as $value.
$value_name
is the class variable name to be used for the 'value' attribute. This parameter is optional and if omitted will default to 'value'. This parameter was introduced in Joomla 1.0.
$text_name
is the class variable name to be used for the 'text' attribute. This parameter is optional and if omitted will default to 'text'. This parameter was introduced in Joomla 1.0.

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.

Examples

Example 1: creating a list with hard coded values:

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

 
// 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() );

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Saturday, 31 May 2008 )
 
< Prev   Next >