demuro1 Posted October 19, 2012 Share Posted October 19, 2012 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 More sharing options...
atar.yosef Posted October 19, 2012 Share Posted October 19, 2012 Try to omit the last else statement. I hope this will work. Link to comment Share on other sites More sharing options...
dsonesuk Posted October 19, 2012 Share Posted October 19, 2012 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 More sharing options...
demuro1 Posted October 20, 2012 Author Share Posted October 20, 2012 dsonesuk that worked. I had to add e.charCode though. I can only guess what the code means but I really appreciate your help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now