I am trying to make some kind of small calculator from scratch. I have a form with 2 input fields and a submit button. When the submit button is pressed, this function is executed. However, I am trying to check whether the values that the user puts in the fields is a number or not. I found the IsNaN function for this, but its not showing the alert it should give when the field has no number as value or when the field is left empty. This is my javascript function right now:
function rekenmachine(){
//Pak de ingevulde getallen
var getal1 = document.getElementById('getal1').value;
var getal2 = document.getElementById('getal2').value;
if(isNaN(getal1)){
alert("Vul a.u.b. in beide velden een getal in.");
}
else{
var uitkomst = parseFloat(getal1) + parseFloat(getal2);
document.getElementById('uitkomst').value = uitkomst;
}
}