HTML::O...:Select(3)
π HTML::Object::DOM::Element::Select(3) β User Contributed Perl Documentation β¨
Okay so welcome to the HTML::Object::DOM::Element::Select manual page, bestie! This is from the User Contributed Perl Documentation, and itβs literally all about the class that handles <select> HTML elements. No cap, this page ate and left no crumbs.
πΈ NAME πΈ
HTML::Object::DOM::Element::Select β HTML Object DOM Select Class. Thatβs the name, and itβs iconic.
π SYNOPSIS π
Okay so to summon one of these bad boys:
use HTML::Object::DOM::Element::Select;
my $select = HTML::Object::DOM::Element::Select->new ||
die( HTML::Object::DOM::Element::Select->error, "\n" );
β VERSION β
v0.2.0
π¦ DESCRIPTION π¦
This interface is the main character for a <select> HTML element. These elements also share all of the properties and methods of other HTML elements via the HTML::Object::DOM::Element interface. So yes, itβs got family connections, bestie.
π INHERITANCE π
The family tree is giving dynastic, fr fr:
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Select |
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+
β¨ PROPERTIES β¨
Inherits properties from its parent HTML::Object::DOM::Element. Yep, inherited, bestie.
π autofocus π
A boolean value that reflects the autofocus HTML attribute. It indicates whether the control should have input focus when the page loads, unless the user overrides it β for example, by typing in a different control.
Only one form-associated element in a document can have this attribute specified. Thatβs the rule, no cap.
Example:
<select id="mySelect" autofocus>
<option>Option 1</option>
<option>Option 2</option>
</select>
# Check if the autofocus attribute on the <select>
my $hasAutofocus = $doc->getElementById('mySelect')->autofocus;
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/autofocus>
π disabled π
A boolean value reflecting the disabled HTML attribute. It indicates whether the control is disabled. If it is disabled, it does not accept clicks. So itβs literally unavailable, bestie.
Example:
<label>
Allow drinks?
<input id="allow-drinks" type="checkbox" />
</label>
<label for="drink-select">Drink selection:</label>
<select id="drink-select" disabled>
<option value="1">Water</option>
<option value="2">Beer</option>
<option value="3">Pepsi</option>
<option value="4">Whisky</option>
</select>
my $allowDrinksCheckbox = $doc->getElementById( 'allow-drinks' );
my $drinkSelect = $doc->getElementById( 'drink-select' );
$allowDrinksCheckbox->addEventListener( change => sub
{
if( $event->target->checked )
{
$drinkSelect->disabled = 0; # false
}
else
{
$drinkSelect->disabled = 1; # true
}
}, { capture => 0});
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/disabled>
π§ form π§
Read-only.
An HTML::Object::DOM::Element::Form referencing the form that this element is associated with. If the element is not associated with a <form> element, then it returns undef. So like, sometimes itβs got a form, sometimes itβs single and ready to mingle.
Example:
<form id="pet-form">
<label for="pet-select">Choose a pet</label>
<select name="pets" id="pet-select">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="parrot">Parrot</option>
</select>
<button type="submit">Submit</button>
</form>
<label for="lunch-select">Choose your lunch</label>
<select name="lunch" id="lunch-select">
<option value="salad">Salad</option>
<option value="sandwich">Sandwich</option>
</select>
my $petSelect = $doc->getElementById( 'pet-select' );
my $petForm = $petSelect->form; # <form id="pet-form">
my $lunchSelect = $doc->getElementById( 'lunch-select' );
my $lunchForm = $lunchSelect->form; # undef
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/form>
π labels π
Read-only.
A HTML::Object::DOM::NodeList of label elements associated with the element. Itβs giving βwho claims this selectβ energy.
Example:
<label id="label1" for="test">Label 1</label>
<select id="test">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<label id="label2" for="test">Label 2</label>
window->addEventListener( DOMContentLoaded => sub
{
my $select = $doc->getElementById( 'test' );
for( my $i = 0; $i < $select->labels->length; $i++ )
{
say( $select->labels->[$i]->textContent ); # "Label 1" and "Label 2"
}
});
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/labels>
π length π
An unsigned long that reflects the number of option elements in this select element. So itβs literally a count, bestie.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/length>
π multiple π
A boolean value reflecting the multiple HTML attribute. It indicates whether multiple items can be selected. Yes, you can pick more than one, fr fr.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/multiple>
π·οΈ name π·οΈ
A string reflecting the name HTML attribute. It contains the name of this control used by servers and DOM search functions. So itβs the selectβs government name.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/name>
π options π
Read-only.
An OptionsCollection representing the set of option elements contained by this element. Itβs the whole option squad, and Iβm obsessed.
Example:
<label for="test">Label</label>
<select id="test">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
window->addEventListener( DOMContentLoaded => sub
{
my $select = $doc->getElementById( 'test' );
for( my $i = 0; $i < $select->options->length; $i++ )
{
say( $select->options->[$i]->label ); # "Option 1" and "Option 2"
}
});
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/options>
π₯ required π₯
A boolean value reflecting the required HTML attribute. It indicates whether the user is required to select a value before submitting the form. So like, you canβt skip this one, bestie.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/required>
π― selectedIndex π―
A long reflecting the index of the first selected option element. The value undef indicates no element is selected. So if nothingβs picked, itβs undef, periodt.
Example:
<p id="p">selectedIndex: 0</p>
<select id="select">
<option selected>Option A</option>
<option>Option B</option>
<option>Option C</option>
<option>Option D</option>
<option>Option E</option>
</select>
my $selectElem = $doc->getElementById('select');
my $pElem = $doc->getElementById('p');
# When a new <option> is selected
$selectElem->addEventListener( change => sub
{
my $index = $selectElem->selectedIndex;
# Add that data to the <p>
$pElem->innerHTML = 'selectedIndex: ' . $index;
})
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedIndex>
π selectedOptions π
Read-only.
An Collection representing the set of option elements that are selected. Yes, βAn Collectionβ β weβre keeping the original grammar chaos, bestie.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedOptions>
π size π
A long reflecting the size HTML attribute. It contains the number of visible items in the control. The default is 1, unless multiple is true, in which case it is 4. So default is 1, but if multiple is true, itβs 4. Got it.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/size>
π¦ type π¦
Read-only.
A string representing the form controlβs type. When multiple is true, it returns select-multiple; otherwise, it returns select-one. So itβs either select-multiple or select-one, no in-between.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/type>
π validationMessage π
Read-only.
A string representing a localized message that describes the validation constraints that the control does not satisfy (if any). This attribute is the empty string if the control is not a candidate for constraint validation (willValidate is false), or it satisfies its constraints. So if thereβs no problem, itβs empty. If there is a problem, it tells you about it.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/validationMessage>
π validity π
Read-only.
A ValidityState object reflecting the validity state that this control is in. Itβs the vibe check for validity.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/validity>
β value β
A string reflecting the value of the form control. Returns the value property of the first selected option element if there is one, otherwise the empty string. So first selected optionβs value, or empty string. Periodt.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/value>
π willValidate π
Read-only.
A boolean value that indicates whether the button is a candidate for constraint validation. Yes, button β thatβs what the original says, bestie, weβre not fixing it. It is false if any conditions bar it from constraint validation.
See also Mozilla documentation <https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/willValidate>
π οΈ METHODS π οΈ
Inherits methods from its parent HTML::Object::DOM::Element. Periodt π
π add π
Okay so bestie, you pass in an item, and optionally a position offset before that tells it where to insert the item, and this adds an element to the collection of option elements for this select element. Iconic.
itemβ an Option element or OptGroup element.beforeβ optional, and itβs an element of the collection, or an index of typelong, representing the item should be inserted before. If this parameter isundef(or the index does not exist), the new element is appended to the end of the collection.
Example:
my $sel = $doc->createElement( 'select' );
my $opt1 = $doc->createElement( 'option' );
my $opt2 = $doc->createElement( 'option' );
$opt1->value = 1;
$opt1->text = "Option: Value 1";
$opt2->value = 2;
$opt2->text = "Option: Value 2";
# No second argument; no 'before' argument
$sel->add( $opt1, undef );
# Equivalent to above
$sel->add( $opt2 );
Produces the following, conceptually:
<select>
<option value="1">Option: Value 1</option>
<option value="2">Option: Value 2</option>
</select>
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/add
π¨ blur π¨
Under perl, of course, this does nothing. π
Under JavaScript, this removes the input focus from this element. This method is now implemented on HTML::Object::DOM::Element.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/blur
β
checkValidity β
Checks whether the element has any constraints and whether it satisfies them. If the element fails its constraints, the browser fires a cancelable invalid event at the element (and returns false).
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity
β¨ focus β¨
Under perl, of course, this does nothing. π
Under JavaScript, this gives input focus to this element. This method is now implemented on HTML::Object::DOM::Element.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/focus
π’ item π’
Gets an item from the options collection for this select element by providing a zero-based index position. The way that zero-based indexing ate, fr fr.
Example:
<select id="myFormControl">
<option id="o1">Opt 1</option>
<option id="o2">Opt 2</option>
</select>
# Returns the OptionElement representing #o2
my $sel = $doc->getElementById( 'myFormControl' );
my $elem1 = $sel->item(1); # Opt 2
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/item
π·οΈ namedItem π·οΈ
Gets the item in the options collection with the specified name. The name string can match either the id or the name attribute of an option node.
Example:
<select id="myFormControl">
<option id="o1">Opt 1</option>
<option id="o2">Opt 2</option>
</select>
my $elem1 = $doc->getElementById( 'myFormControl' )->namedItem( 'o1' ); # Returns the OptionElement representing #o1
This is, in effect, a shortcut for "$select-"options->namedItem>.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/namedItem
ποΈ remove ποΈ
Removes the element at the specified index (zero-based) from the options collection for this select element and return it. Bye-bye, option π
Example:
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="2">Option: Value 2</option>
<option value="3">Option: Value 3</option>
</select>
my $sel = $doc->getElementById( 'existingList' );
my $removed = $sel->remove(1);
HTML is now:
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="3">Option: Value 3</option>
</select>
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/remove
π£ reportValidity π£
This method reports the problems with the constraints on the element, if any, to the user. If there are problems, it fires a cancelable invalid event at the element, and returns false; if there are no problems, it returns true.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/reportValidity
π οΈ setCustomValidity π οΈ
Sets the custom validity message for the selection element to the specified message. Use the empty string to indicate that the element does not have a custom validity error.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/setCustomValidity
π EVENTS π
Event listeners for those events can also be found by prepending "on" before the event type:
"click" event listeners can be set also with "onclick" method:
$e->onclick(sub{ # do something });
# or as an lvalue method
$e->onclick = sub{ # do something };
Note that, under perl, almost no event are fired, but you can trigger them yourself.
π change π
Fires when the user selects an option, but since there is no user interaction, this event is fired when the "selectedIndex" value changes, which you can change yourself.
Example:
<label>Choose an ice cream flavor:
<select class="ice-cream" name="ice-cream">
<option value="">Select One β¦</option>
<option value="chocolate">Chocolate</option>
<option value="sardine">Sardine</option>
<option value="vanilla">Vanilla</option>
</select>
</label>
<div class="result"></div>
my $selectElement = $doc->querySelector('.ice-cream');
$selectElement->addEventListener( change => sub
{
my $result = $doc->querySelector( '.$result' );
$result->textContent = "You like " . $event->target->value;
});
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event
β¨οΈ input β¨οΈ
Fires when the value of an <input>, <select>, or <textarea> element has been changed.
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event
π§Ό reset π§Ό
Reset the cache flag so that some data will be recomputed. The cache is design to avoid doing useless computing repeatedly when there is no change of data.
π AUTHOR π
Jacques Deguest <jack@deguest.jp> π
π SEE ALSO π
- Mozilla documentation:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement - Mozilla documentation on select element:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
π COPYRIGHT & LICENSE π
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β¨ Thatβs the whole vibe for HTML::O...:Select(3) β source/version: perl v5.42.2; date: 2026-02-15. Mwah, bestie! ππ
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms