views:

137

answers:

1

Hi,

Following is the code that i am using. It work in IE but the button click event is not generated properly in firefox:

function trapEnter(btn,hdn, event) {
    var key;
    var isIE = true;
    debugger;
    if (window.event) {
        key = window.event.keyCode;     //IE
        isIE = true;
    }
    else {
        key = event.which;      //firefox
        isIE = false;
    }
    if (key == 13) {

    var btn = document.getElementById(btn);
    if (btn != null) { //If we find the button click it
        document.getElementById(hdn).value = '1'
        btn.click();

        key = 0;
    }
}

}

A: 

I think your function has the wrong parameters. Try this:

function trapEnter(e) {
  e = e || window.event || event;
  var code = e.charCode || e.keyCode || e.which;
  if (code == 13) {
    var btn = document.getElementById('<%= YourButtonID.ClientID %>');
    if (btn != null) { //If we find the button click it
        document.getElementById(hdn).value = '1';
        btn.click();

        key = 0;
    }
  }
}
Tim Schmelter