Reputation: 7973
This my checkbox elements:
<input type="checkbox" name="colors" value="blue" /> Blue <br/>
<input type="checkbox" name="colors" value="green" /> Green<br/>
<input type="checkbox" name="colors" value="yellow" /> Yellow<br/>
How can i get the last value from this multiple checkbox, just clear JS because i have been studying JS and HTML just for 2 days. Thanks.
Upvotes: 0
Views: 140
Reputation: 104775
Use document.querySelectorAll
var checkboxes = document.querySelectorAll("input[name=colors]")
var lastCheckbox = checkboxes[checkboxes.length - 1];
var lastCheckboxValue = lastCheckbox.value;
Upvotes: 1