473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Script For Time-Limited Page View

35
hi all,
i'm developing an application were the time to view a certain page is limited. i also want to alert the user when he has 10 more minutes. i'm using this script but it doesn't work well. can anyone help me to check whats wrong and a tip on how to include the alert?:
Expand|Select|Wrap|Line Numbers
  1. var countdown = "30"
  2. function onclick() {
  3.  
  4.  
  5.      if (countdown > 0) {
  6.         countdown-- }
  7.  
  8.         else {
  9.         document.location="Direction.aspx"
  10.         }
  11.  
  12.         window.status=countdown + " minutes left to finish this Paper."
  13. setTimeout('doCount()',60000)
  14.         }
  15. onclick()
  16.  
thanks guys!
Aug 17 '07 #1
12 1838
epots9
1,351 Expert 1GB
hi all,
i'm developing an application were the time to view a certain page is limited. i also want to alert the user when he has 10 more minutes. i'm using this script but it doesn't work well. can anyone help me to check whats wrong and a tip on how to include the alert?:
Expand|Select|Wrap|Line Numbers
  1. var countdown = "30"
  2. function onclick() {
  3.  
  4.  
  5.      if (countdown > 0) {
  6.         countdown-- }
  7.  
  8.         else {
  9.         document.location="Direction.aspx"
  10.         }
  11.  
  12.         window.status=countdown + " minutes left to finish this Paper."
  13. setTimeout('doCount()',60000)
  14.         }
  15. onclick()
  16.  
thanks guys!
for an alert at 10 minutes try this:
Expand|Select|Wrap|Line Numbers
  1. var countdown = "30"
  2. function onclick() {
  3.  
  4.  
  5.      if (countdown > 0) {
  6.         countdown-- }
  7.         else if(countdown == 10)
  8. {
  9. alert("10 min left");
  10. }
  11.         else {
  12.         document.location="Direction.aspx"
  13.         }
  14.  
  15.         window.status=countdown + " minutes left to finish this Paper."
  16. setTimeout('doCount()',60000)
  17.         }
  18. onclick()
  19.  
  20.  
good luck
Aug 17 '07 #2
acoder
16,027 Expert Mod 8TB
Changed the thread title. Please do not use words such as "Pls" and "help" in the title. Thanks.
Aug 17 '07 #3
mercea
35
for an alert at 10 minutes try this:
Expand|Select|Wrap|Line Numbers
  1. var countdown = "30"
  2. function onclick() {
  3.  
  4.  
  5.      if (countdown > 0) {
  6.         countdown-- }
  7.         else if(countdown == 10)
  8. {
  9. alert("10 min left");
  10. }
  11.         else {
  12.         document.location="Direction.aspx"
  13.         }
  14.  
  15.         window.status=countdown + " minutes left to finish this Paper."
  16. setTimeout('doCount()',60000)
  17.         }
  18. onclick()
  19.  
  20.  
good luck
thanks but i tried it before and it'll work for the first one minute then say error on page!

what else can i do?
thanks
Aug 17 '07 #4
acoder
16,027 Expert Mod 8TB
thanks but i tried it before and it'll work for the first one minute then say error on page!

what else can i do?
thanks
60000 means 60 thousand milliseconds where one millisecond = 1 second, so 60000 is one minute.
Aug 17 '07 #5
--see answer below -- sorry for this bad post
Aug 17 '07 #6
thanks but i tried it before and it'll work for the first one minute then say error on page!

what else can i do?
thanks
It seems in your onclick() function you have a setTimeout to call itself in 60 seconds.
Unless you have doCount() defined elsewhere, you need to call the correct function within the setTimeout.
Please change your line 13 in your original post or line 16 in epots9 reply to the following and it should work as expected.
Expand|Select|Wrap|Line Numbers
  1. setTimeout('onclick()',60000)
  2.  
Aug 17 '07 #7
mercea
35
It seems in your onclick() function you have a setTimeout to call itself in 60 seconds.
Unless you have doCount() defined elsewhere, you need to call the correct function within the setTimeout.
Please change your line 13 in your original post or line 16 in epots9 reply to the following and it should work as expected.
Expand|Select|Wrap|Line Numbers
  1. setTimeout('onclick()',60000)
  2.  
hi,
thanks a lot! i dont know how i missed that. it works well except that using
Expand|Select|Wrap|Line Numbers
  1. var countdown = "31"
  2. function onclick() {
  3.  
  4.      if (countdown > 0) {
  5.         countdown-- }
  6.         else if
  7.         (countdown == 10)
  8. {
  9. alert("YOU HAVE 10 MINS LEFT!");
  10. }
  11.  
  12.         else  {
  13.         document.location="Direction.aspx"
  14.         }
  15.  
  16.         window.status=countdown + " minutes left to finish this Paper."
  17. setTimeout('onclick()',60000)
  18.         }
  19. onclick()
it doesnt display the alert.
Aug 20 '07 #8
acoder
16,027 Expert Mod 8TB
hi,
thanks a lot! i dont know how i missed that. it works well except that using
Expand|Select|Wrap|Line Numbers
  1. var countdown = "31"
  2. function onclick() {
  3.  
  4.      if (countdown > 0) {
  5.         countdown-- }
  6.         else if
  7.         (countdown == 10)
  8. {
  9. alert("YOU HAVE 10 MINS LEFT!");
  10. }
  11.  
  12.         else  {
  13.         document.location="Direction.aspx"
  14.         }
  15.  
  16.         window.status=countdown + " minutes left to finish this Paper."
  17. setTimeout('onclick()',60000)
  18.         }
  19. onclick()
it doesnt display the alert.
Please use CODE tags when posting code. Thanks.

If you look at your if statement, it checks if the countdown is greater than 0. 10 is also greater than 0, so it never enters the else-if statement. To avoid this, first check for 10, then for greater than 0, or move the check for 10 outside this if statement and put it on its own, e.g.
Expand|Select|Wrap|Line Numbers
  1.      if (countdown > 0) {
  2.         countdown--; }
  3.         else  {
  4.         document.location="Direction.aspx";
  5.         }
  6.         if (countdown == 10)
  7. {
  8. alert("YOU HAVE 10 MINS LEFT!");
  9. }
Aug 20 '07 #9
mercea
35
Please use CODE tags when posting code. Thanks.

If you look at your if statement, it checks if the countdown is greater than 0. 10 is also greater than 0, so it never enters the else-if statement. To avoid this, first check for 10, then for greater than 0, or move the check for 10 outside this if statement and put it on its own, e.g.
Expand|Select|Wrap|Line Numbers
  1.      if (countdown > 0) {
  2.         countdown--; }
  3.         else  {
  4.         document.location="Direction.aspx";
  5.         }
  6.         if (countdown == 10)
  7. {
  8. alert("YOU HAVE 10 MINS LEFT!");
  9. }
thank u very much.it works perfectly! my application is actually like a Q&A site were the user has limited time within which to answer the questions. is it possible for the time limit to be varied? for instance the site administrator wants to increase the time to 40mins. how can this be acheived without him having to rewrite the code?
Aug 20 '07 #10
acoder
16,027 Expert Mod 8TB
thank u very much.it works perfectly! my application is actually like a Q&A site were the user has limited time within which to answer the questions. is it possible for the time limit to be varied? for instance the site administrator wants to increase the time to 40mins. how can this be acheived without him having to rewrite the code?
Hmm.. you shouldn't do this on the client-side. I could easily view the source code and change the limit to 1 hour or however many minutes I wish.

You should set this on the server-side. What server-side language are you using for the form processing?
Aug 20 '07 #11
mercea
35
Hmm.. you shouldn't do this on the client-side. I could easily view the source code and change the limit to 1 hour or however many minutes I wish.

You should set this on the server-side. What server-side language are you using for the form processing?
yeah i actually thought that leaving it that way would allow for changes to be made.i'm using ASP.net. so, i could set a variable parameter,server side, that the script will read at run-time. right?
Aug 21 '07 #12
acoder
16,027 Expert Mod 8TB
yeah i actually thought that leaving it that way would allow for changes to be made.i'm using ASP.net. so, i could set a variable parameter,server side, that the script will read at run-time. right?
For something like this, it would be better to do this on the server-side. Perhaps a time should be set from the server with session variables identifying each user. Each question could be retrieved from the server, so that a check can be made for the time or you could periodically update the time from the server. You could use Ajax for this to avoid having to refresh the page each time.

You can combine both server-side and client-side checking, but don't depend on Javascript otherwise it would be too easy to flout the restrictions.

These are some suggestions.
Aug 21 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dennis Roberts | last post by:
I have a script to parse a dns querylog and generate some statistics. For a 750MB file a perl script using the same methods (splits) can parse the file in 3 minutes. My python script takes 25...
5
by: Tim Morrison | last post by:
Is there any easy way to create a change script as illustrated below for all tables within a database? Right now I would have to create a seperate script for each table. I would like to be able...
6
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of...
2
by: codesmithsf | last post by:
I'm using PHP 4.2.2 and Apache 2.0.4.0. A script running on a virtual host had an endless loop in it that brought Apache to its knees. I have max_execution_time=90 and memory_limit=32M to...
3
by: iam980 | last post by:
Hello All. We have tested following SQL script from query analyzer: -- Script begin DECLARE @I int; SET @I = 1; WHILE @I < 10000000 BEGIN SET @I = @I + 1; END -- Script end
13
by: wattersmt | last post by:
Hello, I am trying to write a python cgi that calls a script over ssh, the problem is the script takes a very long time to execute so Apache makes the CGI time out and I never see any output. ...
9
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
4
by: J. Frank Parnell | last post by:
Hi there, I have a list of links which point to e.g. thescript.php?album=somePictures1 thescript.php?album=somePictures2 This list is about 3000 links. Each album may have 500 or more...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
15
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.