Suppose you are examining the script for the orderForm web f…
Suppose you are examining the script for the orderForm web form, whose submit button has the id submitButton. The form includes option buttons for choosing a pizza sauce flavor. The following JavaScript code included in the script will check for a sauce selection when the user clicks the submit button and display a custom error message if a sauce was not chosen. let submitButton = document.getElementById(“submitButton”); submitButton.addEventListener(“click”, validateSauce); function validateSauce() { let sauce = document.forms.orderForm.elements.sauceType; if (sauce.validity.valueMissing) { sauce.setCustomValidity(“”); } else { sauce.setCustomValidity(“Choose a sauce, please”); } }