mercredi 5 avril 2017

If statements in functions not working

For some unknown reason the if statements in the checkID function have stopped working and are only displaying 'OK' no matter what input is entered. I'm not exactly sure what I've done wrong but can someone take a look at my code. At the moment the code only seems to be running the last if statement in the function and only the last message which is "Ok".

This is my HTML:

<!DOCTYPE html>
<html>
<body>
<form name="Cars">
<h1>Car Sales</h1>
<p>Enter Name</p>
<input type="text" style="text-transform: uppercase" name="Name"><br>
<p id="IDName"></p>
<p>Enter ID</p>
<input type="text" name="NameID"><br>
<p id="PersonID"></p>
<br>
<button onclick="return begin()">Calculate</button>
<script src="dfddf.js">   </script>
</form>
</body>

This is my JavaScript:

function begin() {
  var Name = document.forms["Cars"]["Name"].value;
  var NameID = document.forms["Cars"]["NameID"].value;
  var IDName = "";
  var PersonID = "";

var checklength = Name.length;
CheckName();
console.log(checklength, checklength < 100)
var checkIDlength = NameID.length;
checkID();
console.log(checkIDlength, checkIDlength < 100)
return false;


function CheckName(){
  if (checklength >0 && checklength <21)
  {
IDName = "Ok"
  }
  else{
    IDName = "Invalid Name Length";
  }

  document.getElementById('IDName').innerHTML = IDName;
  return false;
}


function checkID(){
  if (checkIDlength !=6)
  {
    PersonID = "Invalid ID Length"
  }
  document.getElementById('PersonID').innerHTML = PersonID


  if (NameID.indexOf('BR') === 0) {
  }
  else {
    PersonID = "Invalid ID Type"
    document.getElementById('PersonID').innerHTML = PersonID

}
   if (isNaN(NameID.Length !=2))
  {
    PersonID = "The Last 2 Digits must be numeric";
  }
  else{
    PersonID = "OK"
    document.getElementById('PersonID').innerHTML = PersonID

  }

}
}

Aucun commentaire:

Enregistrer un commentaire