Page 1 of 1
JS Timer Based on Typing
Posted: Sun Nov 01, 2009 9:31 pm
by jfj3rd
I'm looking to create a timer that activates when a user starts typing in a form field. I need it to pause counting though when the typing stops and continue counting when the typing continues. The final time is calculated upon the user hitting Submit of course.
I figure a JS OnFocus would work but it wouldn't be able to stop the counting if the person stops typing for say a bathroom break or what have you. So JS is a secondary option if you guys can give me some creative ideas for what I really want.
Thanks in advance!
Re: PHP Timer Based on Typing
Posted: Sun Nov 01, 2009 11:16 pm
by califdon
And tell me how PHP will know what a user does, since PHP is a server side language and never is sent to the browser at all????
Re: PHP Timer Based on Typing
Posted: Mon Nov 02, 2009 1:03 am
by jfj3rd
@Califdon my apologies for not being the brightest when it comes to one languages capabilities or another. If I had any idea that PHP wouldn't be able to determine a users actions, I perhaps wouldn't have posted in the first place. While your answer wasn't helpful in one aspect it was in another. I now know that, according to you, PHP cannot pick up the act of typing.
So I still need to figure out some kind of solution or at least a pointing in the right direction. Is Javascript going to be my best direction? What about using a little AJAX?
Yeah I'm talking out of my rear and only pretending I know all of these languages and all of that but if I knew the answer or which way to look I wouldn't be here asking for help so please bear with just one more newbe that doesn't know jack from bob when it comes to most coding.
Re: PHP Timer Based on Typing
Posted: Mon Nov 02, 2009 12:39 pm
by califdon
That was my point, and I'm sorry that I was sarcastic, but I think it accomplished my purpose, to get you to think about how important it is for you to learn the basic facts about web programming before you can even ask meaningful questions. There are two kinds of scripts: those that run at the server (PHP, Perl) and those that run in the browser (Javascript, VBScript). Ajax is not a language, it is a technique that uses Javascript to make a request to a server script and process the results without loading a new page in the browser.
So yes, you are on the right track, if you need to detect what a user does, you can only do it with a client-side script (Javascript or VBScript). That script may take some action within the browser or it may send an Ajax request to the server, if it needs to get more data from a database, for example. You can create a timer with Javascript. There's lots of information online about such routines, or you could now ask your question in a meaningful way in our Javascript forum.
Re: PHP Timer Based on Typing
Posted: Mon Nov 02, 2009 7:41 pm
by John Cartwright
I'm going to go ahead and move this to Javascript forum, since thats where the solution lies.