开发者

Score system based on time in Javascript

开发者 https://www.devze.com 2022-12-18 02:34 出处:网络
I have used a jQuery script in order to have a countdown script on a php page that I am doing, but I would also like to have a score system in it based on the time the user takes to answer some questi

I have used a jQuery script in order to have a countdown script on a php page that I am doing, but I would also like to have a score system in it based on the time the user takes to answer some questions.

I am using some drag and drops and开发者_高级运维 click in a certain link into an image map -which is the only correct link in the webpage- and in the three pages I am using this countdown, but I would like to, once the user has completed the drags&drops or clicked the links, get the number on the countdown just when the user clicked on a "submit" button...but I am not even sure if I can do this.

Alternatively, could I use any countdown script that would let me get the actual number that is being showed just when the user click on the submit button?

Thanks a lot everybody in advance!


Only use the javascript countdown for display purposes, you cannot trust the client.

Keep the count down server side. Store it in the SESSION variable, or in the database.

Javascript is insecure because the client can change it. I could save your page on my machine, open it up, and modify how the timer reports and you'd get a completely different time than you should get. I could also just change the variable using the browsers address bar. The client can always, always change anything in javascript, and you must, absolutely must rely on the server to keep your users honest.


Why not just stash the time (as a numeric value) when you want the timer to start, and then just check the difference when you want to know how long it's been? In other words, you've already got the client computer's clock counting, because that's what clocks do. Just remember what time it was when the drag&drop completes (or whatever point in time serves as your reference), and then check the time again in an event handler for the submit button.

0

精彩评论

暂无评论...
验证码 换一张
取 消