javascript function validate not working

JavaScript functions return undefined if no return value is defined.
EDIT: For your second problem, getElementById is much more reliable when manipulating DOM.

Change your validateForm() function like –

function validateForm() {
    if (document.getElementById('cfname').value === '') {
      document.getElementById('errcfname').innerHTML = "Please enter firstname";
      return false;
    return true;

Reference –

JavaScript does not have a void type, so every function must return a value. The default value is undefined, except for constructors, where the default return value is this.

Browse More Popular Posts

Leave a Comment