Saturday, June 1, 2024
32
rated 0 times [  37] [ 5]  / answers: 1 / hits: 59473  / 15 Years ago, tue, november 17, 2009, 12:00:00

I'm having trouble with some JavaScript that I've written, but only with Internet Explorer 8. I have no problem executing this on Internet Explorer 7 or earlier or on Mozilla Firefox 3.5 or earlier. It also executes properly when I use compatibility mode on Internet Explorer 8.



What I'm doing is overriding the Enter keystroke when a user enters a value into a textbox. So on my element I have this:



<asp:TextBox ID=ddPassword runat=server TextMode=Password onkeypress=doSubmit(event) Width=325></asp:TextBox>


And then I have the following JavaScript method:



function doSubmit(e)
{
var keyCode = (window.Event) ? e.which : e.keyCode;
if (keyCode == 13)
document.getElementById(ctl00_ContentPlaceHolder1_Login).click();
}


Again, this all works fine with almost every other browser. Internet Explorer 8 is just giving me a hard time.



Any help you might have is greatly appreciated.



UPDATE: Thanks everyone for your quick feedback. Both Chris Pebble and Bryan Kyle assisted with this solution. I have awarded Bryan the answer to help with his reputation. Thanks everyone!


More From » internet-explorer-8

 Answers
13

It looks like under IE8 the keyCode property of window.Event is undefined but that same property of window.event (note the lowercase e) has the value. You might try using window.event.



function doSubmit(e)
{
var keyCode = (window.event) ? e.which : e.keyCode;
if (keyCode == 13)
document.getElementById(ctl00_ContentPlaceHolder1_Login).click();
}

[#98294] Friday, November 13, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grayson

Total Points: 36
Total Questions: 113
Total Answers: 95

Location: Tonga
Member since Fri, Aug 21, 2020
4 Years ago
grayson questions
;