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.

Syntax:

object.text;
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:
<head>
    <script type="text/javascript">
        function GetSelected (selectTag) {            
            // the selected option
            var selectedOption = selectTag.options[selectTag.selectedIndex];

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

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content