Answers for "conditional rendering alert if input fields are empty"

0

conditional rendering alert if input fields are empty

function candidateNames() {
  var inputs = document.getElementsByTagName("input");
  var result = [];
  for ( var i = 0; i < inputs.length; i += 1 ) {
      result[i] = inputs[i].value;

      if (inputs[i].value == '') { // check if value is empty
          alert('Need to fill inputs');
          return; // stop the function
      }

}
    document.getElementById("candidateName1").innerHTML = result[0];
    document.getElementById("candidateName2").innerHTML = result[1];
    document.getElementById("candidateName3").innerHTML = result[2];
}

//Event listener to calculate button to call all above functions
document.getElementById("btn").addEventListener("click", calculateVotes, false);

function calculateVotes() {
  candidateNames();
}
Posted by: Guest on July-15-2020

Code answers related to "conditional rendering alert if input fields are empty"

Code answers related to "Javascript"

Browse Popular Code Answers by Language