So I'm making a chess game and my goal is to submit the form just when the user chooses the required piece from the dropdown menu on pawn promotion. But unlike Java where we can add action listeners to objects, JavaScript isn't helping me out.
I've tried this and other possible combination of codes but all in vain.
HTML:
<form id="needpromo" action="dopromo()">
<select>
<option id="promo0" onclick="dopromo()">Bishop</option>
<option id="promo1" onclick="dopromo()">Knight</option>
<option id="promo2" onclick="dopromo()">Rook</option>
<option id="promo3" onclick="dopromo()">Queen</option>
</select>
</form>
JavaScript:
for(let i=0;i<4;i++)
document.getElementById(`promo${i}`).addEventListener("click",function()
{
//required action
}
How can I achieve this?