function clearForm() { //https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements //get all 'fields' var inputs = document.getElementById("mPoloForm2").elements; console.log("Clearing the form..."); // Iterate over the form controls for (var i = 0; i < inputs.length; i++) { //log which elements are which in the inputs array console.log("i = " + i); console.log(inputs[i].nodeName); console.log(inputs[i].value); //text fields if (inputs[i].nodeName === "INPUT" && inputs[i].type === "text") { // empty all text field values inputs[i].value = ""; } //radio button processing if (inputs[i].nodeName === "INPUT" && inputs[i].type === "radio") { // Update radio button setting to 'unspecified' console.log("radio: " + inputs[i].value); if(inputs[i].value === "unspecified"){ inputs[i].checked = true; } } //text area processing if(inputs[i].nodeName === "TEXTAREA"){ inputs[i].innerHTML = ""; } //select menu processing if(inputs[i].nodeName === "SELECT"){ inputs[i].selectedIndex = 0; } }//end for loop }//end function clearForm function resetForm(){ //get all 'fields' console.log("Resetting the form..."); var inputs = document.getElementById("mPoloForm2").elements; // Iterate over the form controls //because we 'logged' the clearForm process, we know what element is //associated with what number. As long as we don't change the form, we're good //with the selections below. for (var i = 0; i < inputs.length; i++) { switch(i){ case 1: inputs[i].value = ""; break; case 2: inputs[i].value = ""; break; case 3: inputs[i].value = ""; break; case 4: inputs[i].selectedIndex = ""; break; case 5: inputs[i].innerHTML = ""; break; case 6: inputs[i].checked = true; }//end switch }//end for loop }//end function resetForm