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();
}
Also in JavaScript:
- javascript create script tag
- react hook form submit outside form
- How can I upload files asynchronously
- angular generat model
- js modulo not working
- javascript filter and order
- CocoaPods could not find compatible versions for pod "ReactCommon/jscallinvoker"
- jquery infinite scroll
- multidimensional array javascript
- displaying the date react
- react native text-input-mask this.props.refInput
- javascript switch statement multiple cases
- react-native-screens
- inverser l'ordre des item d'un array js
- javascript destructing
- setinterval nodejs
- javascript pad with leading zeros
- jquery parsexml get attribute
- cookie clicker hack
- What is the correct JavaScript syntax for opening a new window called "w2" ?
- js unique using set
- comments in js
- string length jquery
- find highest value in array javascript