homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Reloading page by pressing enter
Language flash card site

10+ Year Member

Msg#: 12171 posted 8:46 am on Mar 18, 2006 (gmt 0)

I have always used a standard method to get my PHP sites to work and I am finding solving this one a bit of a mind bender. I would appreciate some help. It sounds simple but I am not getting any success.

I need to get a page to reload repeatedly on pressing enter. There is no user input form and the user will exit by clicking a link.

The page is a flash card type operation for a non-comercial site teaching people how to speak an endangered language. (It is has 20,000 people studying it a year according to the available statistics.) The idea is that the page creates
a randomish but gramatically correct sentence which the user then repeats to themselves before pressing enter to get the next sentence.

Could someone please suggest an outline of usable code. I have the flash cards working but currently have to click reload which is less than ideal.



5+ Year Member

Msg#: 12171 posted 10:14 am on Mar 18, 2006 (gmt 0)

That requires some sort of javascript

<script language="JavaScript">

function init() {

document.onkeydown = function(e) {

if (!e) e = window.event;
var code = e.keyCode;
if (code == 13) // 13 is Enter Key
window.location = self.location;


window.onload = init;

The code says, when the page loads, run the init function. The init function sets an event based function, which says when someone presses a key, this is the function.

For keyboard based events, there's a keyCode property associated with the event, which is where e.keyCode comes from.

I'm not sure if it's different for Mac/Linux machines, but on Windows, 13 is the key code for the Enter button.

So in all, it says "when a user presses a key, determine what key they pressed. if they pressed the Enter key, go to a location. In this case, we're reloading so, self.location works.

I just put this code together real quick and tested in firefox 1.0 and IE6. Might not be fully cross-platform/cross-browser, but it's a starting point.


10+ Year Member

Msg#: 12171 posted 7:31 pm on Mar 18, 2006 (gmt 0)

Thanks. As an old 6502 machine code programmer I recognise 13(hex 0D) as the ASCII code for enter so it should work on all platforms. (A9 OD 20 EE FF used to print a carrage return for me on my old system.)
Like most serious coders I run linux :-) I have tried it so far in Epiphany and Konqueror. The latter fails to operate it but I have encountered funny javascript problems with it before.

That is fine thanks a lot. For those people with a problem browser I can put a link on the page to help them get help and tell them to click on reload if all else fails.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved