0

Hi All,

I'm having problem with the onkeypress attribute, I'm not sure if my code is right. When pressing the enter button, the javascript function would work on IE but not in Firefox. I'm not sure if the event keyCode is being recognized by Firefox or if I'm missing something...

Here's a code snippet of my code:

<td width="270px"><input type="text" id="searchB" value="" style ="font-family:Verdana; font-size:10pt; width: 270px; height:100% ;" onkeypress="enterHere();" onFocus="this.select();" ></td>


<script language="javascript" type="text/javascript">
function enterHere()
{
if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
    { 
        find();
    }       
}
</script>

Can anyone help me on this...????

Thanks... :)

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
4
Views
9 Years
Discussion Span
Last Post by ~s.o.s~
0

>When pressing the enter button, the javascript function would work on IE but not in Firefox.
This is because, in Firefox, the event is passed as a parameter to the event handler. event property of the window object is IE only.

function enterHere(e)
{
    e = e || window.event;
    var code = e.keyCode || e.which;
    if(code == 13)
        find();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.