Im trying to input data from a form into an array, everything is going fine but i've noticed even when submitting empty inputs it still records it into my array, im trying to do a IF statement to check if the input field "Name" is empty then restart function and alert them its empty
right now its doing the opposite, alerting them its empty when its not visa versa, I got it to work the other way around but ended up losing that save and forgot how i did it, I also couldnt figure out how to restart that function (to avoid it being added to the array) heres my code,
function addRecord(){
employee.name = document.getElementById('name').value;
employee.age = document.getElementById('age').value;
employee.position = document.getElementById('position').value;
if(name.length == 0){
alert('Do you not have a name, mate?');
return false;
}
employeeList.push(employee);
employee = new Object();
writeRecords();
}
Thanks!
Try something like this:
if(!employee.name){
alert('Do you not have a name, mate?');
return
}
You can also use this logic for checking age and position.