You are here: Reference > JavaScript > client-side > HTML DOM > properties > text (optgroup, option)

text property (optgroup, option)

Browser support:
Sets or returns a string that represents the text of an option element.
If the value property is not specified for a selected option element, then the text content will be sent to the server when the container form is submitted.


You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that sets or retrieves the text of the object.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the text property:
    <script type="text/javascript">
        function GetSelected (selectTag) {            
            // the selected option
            var selectedOption = selectTag.options[selectTag.selectedIndex];

            alert (selectedOption.text);
    <select multiple="multiple" id="mySelect" onchange="GetSelected (this);">
        <option selected="selected">Peach</option>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content