function submitAction(action) {
  const submitDiv = document.querySelector("#submitDiv");
  const formSubmitButton = document.querySelector("button");

  const existingActionSpan = document.querySelector(".submittedMessage");
  if (existingActionSpan) {
    submitDiv.removeChild(existingActionSpan);
  }

  const newActionSpan = document.createElement("span");
  newActionSpan.classList.add("submittedMessage");

  submitDiv.appendChild(newActionSpan);
  if (action == "fail") {
    newActionSpan.innerHTML = "Failed to submit form. Please check form fields.";
    newActionSpan.style.color = "red";
    formSubmitButton.innerHTML = "Re-Submit";
    formSubmitButton.style.background = "red";
  }
  else {
    formSubmitButton.style.background = "green";
  }
}
// function to add a div to the <form> displaying success or failure when submitted
function to add a div to the  displaying success or failure when submitted
function to add a div to the displaying success or failure when submitted
function submitAction(action) {
  const submitDiv = document.querySelector("#submitDiv");
  const formSubmitButton = document.querySelector("button");
  const existingActionSpan = document.querySelector(".submittedMessage");
  if (existingActionSpan) {
    submitDiv.removeChild(existingActionSpan);
  }
  const newActionSpan = document.createElement("span");
  newActionSpan.classList.add("submittedMessage");
  submitDiv.appendChild(newActionSpan);
  if (action == "fail") {
    newActionSpan.innerHTML = "Failed to submit form. Please check form fields.";
    newActionSpan.style.color = "red";
    formSubmitButton.innerHTML = "Re-Submit";
    formSubmitButton.style.background = "red";
  }
  else {
    formSubmitButton.style.background = "green";
  }
}
function submitAction ( action ) { const submitDiv = document . querySelector ( "#submitDiv" ) ; const formSubmitButton = document . querySelector ( "button" ) ; const existingActionSpan = document . querySelector ( ".submittedMessage" ) ; if ( existingActionSpan ) { submitDiv . removeChild ( existingActionSpan ) ; } const newActionSpan = document . createElement ( "span" ) ; newActionSpan . classList . add ( "submittedMessage" ) ; submitDiv . appendChild ( newActionSpan ) ; if ( action == "fail" ) { newActionSpan . innerHTML = "Failed to submit form. Please check form fields." ; newActionSpan . style . color = "red" ; formSubmitButton . innerHTML = "Re-Submit" ; formSubmitButton . style . background = "red" ; } else { formSubmitButton . style . background = "green" ; } }
function to add a div to the <form> displaying success or failure when submitted
function to add a div to the <form > displaying success or failure when submitted