I have 2 <buttons>
in my html code, and one of them has an onclick
function, but the other is just a button I haven't defined yet. The weird thing is that the button that hasn't been defined, has the same onclick
property as the other. Could someone please explain why this is happening?
Here is a code snippet:
saveRuleSelections: function() {
let blackjackRules = [];
let rules = document.getElementsByClassName("rule");
for (let i = 0; i < rules.length; i++) {
blackjackRules.push(rules[i].value);
}
let jsonBlackjackRules = JSON.stringify(blackjackRules);
localStorage.setItem("blackjackRules", jsonBlackjackRules);
document.getElementById("rules_overlay").style.display = "none";
}
<form>
<p>Surrender Allowed:
<select class="rule">
<option value="early">Early</option>
<option value="late">Late</option>
<option value="no" selected>No</option>
</select>
</p>
<button id="select_rules_button" onclick="trueCountApp.saveRuleSelections()">Select Rules</button>
<button>Restore Default</button>
</form>