How to Retrieve the Value of a Selected Checkbox in JavaScript
Checkboxes are used to select one or more options from a list. In the provided code snippet, there are two checkbox inputs with values "3" and "1." To retrieve the value of the selected checkbox, we can use JavaScript.
Solution:
To obtain the value of the sole checked checkbox, use the following code:
<code class="javascript">document.querySelector('.messageCheckbox').checked;</code>
In this code, .messageCheckbox selects the checkbox with the specified class name. The .checked property returns a Boolean value indicating whether the checkbox is checked (true) or not (false).
The above is the detailed content of How to Get the Value of a Selected Checkbox in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!