# Validation Not Working (JavaScript)

**URL:** <https://forum.kirupa.com/t/validation-not-working-javascript/281300>\
**Category:** web dev\
**Created:** [February 7, 2009, 12:44am UTC](https://forum.kirupa.com/t/validation-not-working-javascript/281300 "2009-02-07T00:44:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Obi\_Wan](https://avatars.discourse-cdn.com/v4/letter/o/e99b99/32.png) [@Obi\_Wan](https://forum.kirupa.com/u/Obi_Wan)\
**Post date:** [February 7, 2009, 12:44am UTC](https://forum.kirupa.com/t/validation-not-working-javascript/281300/1 "2009-02-07T00:44:28Z")

</div>

Hey every one I am creating a simple form validation and for some reason it executes an if statement even when the conditions are met. Any help would be awesome.

```auto

function validateBannerForm()
{
    // initialize variables
    var at = document.getElementById("emailAddress").value.indexOf("@");
    var zip = document.getElementById("zipCode").value;
    var firstName = document.getElementById("firstName").value;
    var lastName = document.getElementById("lastName").value;
    var submitOK = "true";
    
    // check first name is not empty, null and is not > 20
    if(firstName.length > 20 || firstName.value == null || firstName.value =="")
    {
        // message to user if name is empty, null or more than 20 characters
        // display error panel div with specific message
        var errorMessage = document.getElementById("errorPanel");
        document.getElementById('errorPanel').style.visibility="visible";
        errorMessage.innerHTML = "Please provide us with your name, also your first name cannot be more than 20 letters.";
        submitOK="false";
    }
    
    // check last name is not empty, null and is not > 30
    if(lastName.length > 30 || lastName.value == null || lastName.value =="")
    {
        var errorMessage = document.getElementById("errorPanel");
        document.getElementById('errorPanel').style.visibility="visible";
        errorMessage.innerHTML = "What's your last name, also your last name cannot be more than 30 letters.";
        submitOK="false";

    }
    else
    {
        alert("Carry On Lad");
    }
    
}

```
