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... :)

>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();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.