NAME

HTML::DOM::Element::Option - A Perl class for representing 'option' elements in an HTML DOM tree

VERSION

Version 0.054

SYNOPSIS

use HTML::DOM;
$doc = HTML::DOM->new;
$elem = $doc->createElement('select');

$elem->focus();
$elem->blur();

# $elem->add(...)    # not yet
# $elem->remove(...) # implemented

$elem->options; # a list of 'option' elements

$elem->name('foo') # set attribute
$elem->type;       # get attribute
$elem->tagName;
# etc.

DESCRIPTION

This class implements 'select' elements in an HTML::DOM tree. It implements the HTMLSelectElement DOM interface and inherits from HTML::DOM::Element (q.v.).

METHODS

In addition to those inherited from HTML::DOM::Element and its superclasses, this class implements the following DOM methods:

defaultSelected
disabled
label

Each of these returns the corresponding HTML attribute (the 'selected' attribute in the case of defaultSelected). If you pass an argument, it will become the new value of the attribute, and the old value will be returned.

form

Returns the form containing this input element.

text

Returns the option's text label.

index

Returns the index of this option in it's 'select' element's options array. You can pass an argument to set it. In that case, the option will be moved to a different place in the tree. (This is actually contrary to the DOM Level 2 specification, which makes it read-only, but Level 1 supported this, and I find feature deletion very disagreeable.)

selected

Returns a boolean indicating whether the option is selected. If an argument is passed, it becomes the new state and the old is returned.

value

Returns the value of the option, that is, the 'value' attribute, if present, or the text content otherwise.

If the calling package is HTML::Form or WWW::Mechanize, the return value will be undef if the option is not selected. With an undef argument the option will be deselected. If an argument is given that is the same as the value, the box will be checked. If any other argument is passed, it will die.

In addition, the following methods are provided for compatibility with WWW::Mechanize:

type

Returns the string 'option'.

name

Returns the name of the enclosing 'select' element.

possible_values

This returns a list with undef for the first element and the option's value for the second.

form_name_value

Returns a list of two items: (0) the name of the field and (1) the value, *if* it is selected.

SEE ALSO

HTML::DOM

HTML::DOM::Element

HTML::DOM::Element::Form

HTML::DOM::Element::Select

HTML::DOM::Collection::Options