Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: create react app theme_color 
Javascript :: store current date in chrome storage extension 
Javascript :: missing json after pyinstaller 
Javascript :: universal apollo kit 
Javascript :: replace array element javascript stack overflow 
Javascript :: set up chrome dev tools adonisjs 
Javascript :: react $ r component instance console 
Javascript :: javascript requestanimationframe stack overflow 
Javascript :: React looping hooks to display in other hook 
Javascript :: lemon get node from id 
Javascript :: mindfusion calendar 
Javascript :: how enable custom css and js vscode ubuntu 
Javascript :: kendo jquery listview 
Javascript :: mixin in javascript mdn 
Javascript :: ar.js getting started 
Javascript :: promises and not callbacks 
Javascript :: JS glob to regex 
Javascript :: javascript repace enter event with another character 
Javascript :: eliminare spazi inizio e fine stringa javascript 
Javascript :: npm react router 6.0.0-alpha.2 
Javascript :: rxjs que recibe como parametro un observable 
Javascript :: es6 1 to one 
Javascript :: js background color to null 
Javascript :: stopper un intervalle javascript 
Javascript :: javascript sanitize input slug 
Javascript :: cargar datos de un id con inner join vue js 
Javascript :: removeeventlistener not working in class javascript 
Javascript :: video pop js 
Javascript :: semantic UI react focus on input 
Javascript :: 1.047222170078745 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =