/****************************************************************** * * * JavaScript to run the pizza order form. * * * * Author: A. Student (put your name here) * * * * Date Created: October xx, 2013 * * * *******************************************************************/ /* This function defines the required event listeners for the various form elements. */ window.onload = function () { var elem; startForm(); // Define event listeners for the pizza type radio buttons. var radios = document.getElementsByName("pizza"); for (var i = 0, max = radios.length; i < max; i++) { elem = radios[i]; if (elem) { elem.addEventListener("click", costPizzaType, false); } else { alert('oops - error adding listener to pizza element'); } } // Define event listener for the pizza size selection. elem = document.getElementById("size"); if (elem) { elem.addEventListener("change", costPizzaSize, false); } else { alert('oops - error adding listener to size element'); } // Define event listeners for the pizza toppings checkboxes. checkbox = document.getElementsByName("topping[]"); for (var i = 0, max = checkbox.length; i < max; i++) { elem = checkbox[i]; if (elem) { elem.addEventListener("click", costTopping, false); } else { alert('oops - error adding listener to topping element'); } } // Define event listeners for the pizza quantity. elem = document.getElementById("quantity"); if (elem) { elem.addEventListener("change", getQuantity, false); } else { alert('oops - error adding listener to quantity element'); } // Define event listener for the reset button. buttons = document.getElementsByTagName("input"); for (var i = 0, max = buttons.length; i < max; i++) { var myName = buttons[i].getAttribute("type"); if (myName && myName.indexOf("reset") == 0) { buttons[i].addEventListener( "click", resetForm, false ); } } } /* end function window.onload */ /****************************************************************** * * * Lab 5 work starts from this point: * * * *******************************************************************/ function costPizzaType() { /* Need to determine which of the radio buttons was clicked - that one will be the only one that has the checked property. */ /* To be written in lab 5 */ } function costPizzaSize() { /* To be written in lab 5 */ } function costTopping() { /* Need to determine which of the checkboxes was clicked - that one will be the one(s) having the checked property. */ /* To be written in lab 5 */ } function getQuantity() { /* To be written in lab 5 */ } function calcTotal() { /* To be written in lab 5 */ } function startForm() { /* To be written in lab 5 */ } function resetForm() { /* To be written in lab 5 */ } /****************************************************************** * * * End of order.js * * * *******************************************************************/