Element
JavaScript: Element
Categories:
Input
Input checked
// checked
document.getElementById('myRadio').checked = true;
document.getElementById('myRadio').checked = "checked";
// unchecked
document.getElementById('myRadio').checked = false;
Select
Get / Set select option value
let select_element = document.querySelector('#mySelect');
// Get
let selected_value = select_element.value;
// Set
select_element.value = 'KJ';
Disable selected element
let select_element = document.querySelector('#mySelect');
select_element.disabled = true;
select_element.disabled = false;
Get select option text
<select onChange="getSelectOptionText(this);">
<option value="1">Dog</option>
<option value="2">Cat</option>
<option value="3">Bird</option>
</select>
function getSelectOptionText(select_element) {
let select_element_options = select_element.options;
let select_element_selected_index = select_element.selectedIndex;
let select_element_option_text = select_element_options[select_element_selected_index].text;
alert(select_element_option_text);
}
Reference
- javascript - checked = “checked” vs checked = true - Stack Overflow
- html - Get selected option text with JavaScript - Stack Overflow
- Change Selected Option in JavaScript [With Examples]
- HTML DOM Select disabled Property