Your function's logic doesn't make sense as it is, but maybe because it's a sample. I'll first guess what you are trying to achieve, then show you a possible solution.
First, regarding the name of your function validateFields, I suppose you need to check if entries (ns1 and ns2 in your example) contain valid data.
So, you might want your function to return a boolean (true or false) if the fields are erroneous.
Your current function doesn't check the 2 entries, and there is only a return when nameserverone is null (which doesn't make sense, or maybe it's what you want).
"use strict";
function validateFields() {
var nameserverone = document.getElementById("ns1").value;
var nameservertwo = document.getElementById("ns2").value;
if(nameserverone === null || nameserverthow === null) {
// one of the entry is empty, we return false
console.log("one of the servers' name is null");
return false;
}
else {
// both entries contain data, should be Ok
return true;
}
}
I would recommend to try having only ONE return in your functions no matter what, such fix would do:
"use strict";
function validateFields() {
var nameserverone = document.getElementById("ns1").value;
var nameservertwo = document.getElementById("ns2").value;
var status;
if(nameserverone === null || nameservertwo === null) {
// one of the entry is empty, we return false
console.log("one of the servers' name is null");
status = false;
}
else {
// both entries contain data, should be Ok
status = true;
}
return status;
}