0

I have an unusual error as follows. When I am using my webpage in IE 32bit. In all other browsers it works fine. My error as follows:

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)
Timestamp: Mon, 23 May 2016 14:53:02 UTC


Message: 'which' is null or not an object
Line: 37
Char: 2
Code: 0

My code as follows:

function btn_contactus_clicked() {
    window.location.href = "ContactUs.jsp";
}


function btn_login_click()
{
    //if (typeof alert_vu !== "undefined") { 
      //  tcalert_close("alert_vu");
    //}

    document.getElementById("msg").value = "";

    if (document.getElementById("input_username").value.trim() === "") {
        document.getElementById("msg").value = "Invalid user name!";
    } else {
        if (document.getElementById("input_password").value.trim() === "") {
            document.getElementById("msg").value = "Invalid password!";
        } else {
            //Add checks for valid username from db here
        }
    }
    if (!(document.getElementById("msg").value === "")) {
        // One or more values entered is incorrect
        tcalert("alert_login", document.getElementById("msg").value);
    } else {
        // All values entered are good
        document.getElementById("alert_login").innerHTML = "";
        document.form_login.submit();
    }
}

document.onkeydown = function(e) { submitClick(e);};

function submitClick(e){

    if(e.which === 13){
        btn_login_click();
    }
}

Please guide me what is the error. It is a simple login page.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Santhucool
  • 1,656
  • 2
  • 36
  • 92
  • 1
    That means IE8 does not support `e.which`, you can simply do a `console.log(e)` to see what is supports, perhaps `e.keyCode`? – Daniel Cheung May 23 '16 at 15:32
  • This means it will support IE9 and after that right? – Santhucool May 23 '16 at 15:34
  • 1
    Sorry, I'm not too familiar with IE version, but do look into this question's answer: http://stackoverflow.com/questions/13495291/jquery-javascript-keypress-function-not-working-on-ie8 – Daniel Cheung May 23 '16 at 15:36
  • 1
    Most likely a duplicate to ['data' is null or not an object IE8](http://stackoverflow.com/questions/17609468) `[...]On IE8 and earlier, no argument is passed into event handlers. Instead, you look at the global event variable[...]` – t.niese May 23 '16 at 16:48
  • 1
    `e.which' is a nonstandard event property and a deprecated one, use the universally supported `event.keyCode` – Bekim Bacaj May 23 '16 at 17:01
  • @ Bekim Bacaj tried e.KeyCode but now getting error as `'KeyCode' is null or not an object` – Santhucool May 25 '16 at 06:05

0 Answers0