MrSSS16
MrSSS16

Reputation: 473

Simple JavaScript not working?

Why isn't this simple JavaScript validation not working ?? The first condition run through but the second isn't going through ??

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">     
        function process(){
            var val = document.getElementById('usrIN').value;
            var uppVer = val.toUpperCase();
            if(val == "" || val == NULL){
                alert ("Must fill in input");
            }else if (val !== uppVer){
                alert("Must be upper case");
            }
        }
    </script>
</head>
<body>
<form type="post" id="frmMain" />
    <p>Insert name in upper case <input type="text" maxlength="25" id="usrIN"/></p>
    <a href="#" onClick="process();"> <img src="button.jpeg"  ></a>
</form>
</body>

Upvotes: -1

Views: 164

Answers (2)

Hayk Martiros
Hayk Martiros

Reputation: 2186

NULL is not defined in javascript - use null or undefined.

See here:

http://jsfiddle.net/EZqhN/

Upvotes: 2

Pete
Pete

Reputation: 2558

In JavaScript, null is lowercase. Also, your use of == "" will also cover a null or undefined variable. Also, you probably didn't mean to do an else if(), you probably meant to just do a second if if there's no dependency on the former failing for the latter to execute.

Upvotes: 2

Related Questions