Jump to content

onkeypress isn't working in firefox


demuro1

Recommended Posts

hello all. I am making a catalog page for a class I am in. I'm still fairly new to javascript but I am having an issue with an onkeypress. It works in safari and IE but not in firefox. Does anyone have any suggestions? I'd appreciate any help you can provide. Thanks

function keystrokeSubmit(text){  var prskeyrtrn = event.keyCode || event.which;  if (prskeyrtrn == 13 && text.id == 'searchField')    {    search();    document.getElementById('searchField').value = 'search';   }  else if (prskeyrtrn == 13 && text.id == 'pageNumber')   {    pageNumber('Current Page');   }  else{}}

<table align="right">	 <tr><td><u>You Are on page:</u></td></tr>	 <tr><td><input type="text" id="pageNumber" value="0" onkeypress=keystrokeSubmit(this)></td></tr>    </table>

Link to comment
Share on other sites

You have not defined what 'event' refers to? when function is called try this

function keystrokeSubmit(text,e){ e = e? e : window.event;var prskeyrtrn = e.keyCode? e.keyCode : e.which? e.which : null;  if (prskeyrtrn == 13 && text.id == 'searchField')   {    search();    document.getElementById('searchField').value = 'search';   }  else if (prskeyrtrn == 13 && text.id == 'pageNumber')   {    pageNumber('Current Page');   }  else{ pageNumber("I give up! i'm going home")}}function pageNumber(a) {alert(a)}

<table align="right">		 <tr><td><u>You Are on page:</u></td></tr>		 <tr><td><input type="text" id="pageNumber" value="0" onkeypress="keystrokeSubmit(this,event)"></td></tr>    </table>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...