How to to periodically call a VBscript function to update a value, similar to that of a live clock showing live update of seconds

I'm developing an intranet for a school. I've written a basic ASP/VBScript function to return a value displaying what the current period is, and I need this to dynamically update live in the page, without a page refresh (much the same way as you might see the seconds tick by when deisplaying a clock in a page).

The code has actually been broken down into two functions, the second being simply holding a response.write, which helped when I was experimenting with different solutions. I can change this back to a simple <%=Periodstate()%> but thought I'd leave it as is for now, in case there is a way of calling just that function? I'm not exactly a noob, but noither am i a nerd.

I think what I'm looking for is something like a javascript "timeout" or "interval"
<%
 
 Function PeriodState()
 
 
	Dim TWDate
 
	TWDate= WeekDay(Now())
 
	Dim TWTime
 
	TWTime= TimeValue(Now())
 
 
If TWDate =1  Then DayState="Sunday"_
Else IF TWDate  = 7 Then DayState="Saturday"_
Else DayState="Weekday"_
 
End IF 
 
 
If (DayState = "Weekday") And (TWTime > "08:39") And (TWTime < "08:54") Then  
       PeriodState = "Chapel"  
           ElseIf (DayState = "Weekday") And (TWTime > "08:54") And (TWTime < "09:54") Then  
       PeriodState = "Lesson 1"  
           ElseIf (DayState = "Weekday") And (TWTime > "09:55") And (TWTime < "10:49") Then  
       PeriodState = "Lesson 2"  
           ElseIf (DayState = "Weekday") And (TWTime > "10:50") And (TWTime < "11:19") Then  
       PeriodState = "The Half"  
           ElseIf (DayState = "Weekday") And (TWTime > "11:20") And (TWTime < "12:19") Then  
       PeriodState = "Lesson 3"  
           ElseIf (DayState = "Weekday") And (TWTime > "12:20") And (TWTime < "13:14") Then  
       PeriodState = "Lesson 4"  
           ElseIf (DayState = "Weekday") And (TWTime > "13:15") And (TWTime < "13:59") Then  
       PeriodState = "Lunch"  
           ElseIf (DayState = "Weekday") And (TWTime > "14:00") And (TWTime < "14:19") Then  
       PeriodState = "Tutor Period"  
           ElseIf (DayState = "Weekday") And (TWTime > "14:20") And (TWTime < "15:19") Then  
       PeriodState = "Lesson 5"  
           ElseIf (DayState = "Weekday") And (TWTime > "15:20") And (TWTime < "16:14") Then  
       PeriodState = "Lesson 6"  
           ElseIf (DayState = "Weekday") And (TWTime > "16:15") And (TWTime < "17:29") Then  
       PeriodState = "After Four"  
           ElseIf (DayState = "Weekday") And (TWTime > "17:30") And (TWTime < "18:29") Then  
       PeriodState = "First Prep"  
           ElseIf (DayState = "Weekday") And (TWTime > "18:30") And (TWTime < "19:29") Then  
       PeriodState = ""  
           ElseIf (DayState = "Weekday") And (TWDate = "3") OR (TWDate = "5") AND (TWTime > "19:30") And (TWTime < "20:59") Then  
       PeriodState = "Second Prep (Late)"  
           ElseIf (DayState = "Weekday") And (TWDate = "2") OR (TWDate = "4") OR (TWDate = "6") AND (TWTime > "19:30") And (TWTime < "20:29") Then  
       PeriodState = "Second Prep"  
           ElseIf (DayState = "Weekday") And (TWDate = "3") OR (TWDate = "5") AND (TWTime > "21:00") And (TWTime < "21:29") Then  
       PeriodState = ""  
           ElseIf (DayState = "Weekday") And (TWDate = "2") OR (TWDate = "4") OR (TWDate = "6") AND (TWTime > "20:30") And (TWTime < "21:29") Then  
       PeriodState = ""  
	  	   ElseIf (DayState = "Weekday") And (TWTime > "21:30") And (TWTime < "22:30") Then  
       PeriodState = "Quiet Time"  
           ElseIf (DayState = "Saturday") And (TWTime > "08:29") And (TWTime < "09:14") Then  
       PeriodState = "Lesson 1"  
           ElseIf (DayState = "Saturday") And (TWTime > "09:15") And (TWTime < "09:59") Then  
       PeriodState = "Lesson 2"  
           ElseIf (DayState = "Saturday") And (TWTime > "10:00") And (TWTime < "10:44") Then  
       PeriodState = "Lesson 3"  
           ElseIf (DayState = "Saturday") And (TWTime > "10:45") And (TWTime < "11:29") Then  
       PeriodState = "Lesson 4"  
           ElseIf (DayState = "Saturday") And (TWTime > "11:30") And (TWTime < "11:54") Then  
       PeriodState = "The Half"  
           ElseIf (DayState = "Saturday") And (TWTime > "11:55") And (TWTime < "12:45") Then  
       PeriodState = "Study Period"  
           ElseIf (DayState = "Saturday") And (TWTime > "12:45") Then  
       PeriodState = "Enjoy Your Weekend!"  
	   
	   ElseIf (DayState = "Sunday") Then  
       PeriodState = "Enjoy Your Weekend!"  
	   
	   
       Else    
	   PeriodState = ""
	   
	   End If 
	   
	
 
End Function 
 
 
 
%>
 
<% Function writePeriod
   
      response.write PeriodState()	
 
End Function %>
 
<%Call writePeriod %>

Open in new window

tony_wheelerAsked:
Who is Participating?
 
schalcraftConnect With a Mentor Commented:
You have to remember that the asp code is run at the web server the generate the html ouput, but it only does so when a client requests the web page. Once the web page has been generated and sent back to the client, the web server can no longer push out updates to the clients.
You will need a client side script (ie javascript) with a timer to either update the output field, or to request the server to re-generate the web page.
If you need to have flexibility to alter the javasript, the you can use the asp code to write out different javacode based on the day the page is loaded.
0
 
SStoryConnect With a Mentor Commented:
What about Javascript and DHTML?
0
 
tony_wheelerAuthor Commented:
>Thanks SStory

Well, this is a very small additional component to an asp template within our new Content Management System, which i originally thought would be quick and dirty! I don''t know enough about Javascript or DHTML to know where to start... at least with ASP I got half-way there!

I just thought I'd stick with ASP and try to find something that maybe went:
1: Write function value > 2: wait five seconds > 3: delete function value > 4: Loop back to 1

But if it's not possible, I'll guess I'll start to look at alternatives...
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
tony_wheelerAuthor Commented:
Thanks for reminding me Schalcraft... good point! I guess that's why all the solutions i've come across only seem to be in Javascript! Okay, I'll take a look at puting something like that together!
0
 
tony_wheelerAuthor Commented:
Thanks Folks
0
 
SStoryCommented:
Well javascript has the feel of C.  There are plenty of samples. I don't know it perfectly either. I just look for samples and online manuals:
http://www.w3schools.com/JS/default.asp

I haven't done much DHTML, but what I did was neat.  Basically you change the content within a tag or ID dynamically on the client side.  So javascript would do what your server side code is doing.  It is similar.  It is case sensitive

if (DayState == "Weekday") && (TWTime > "08:39") && (TWTime < "08:54") {
  //do some stuff
}

Here's tutorials on DHTML:
http://www.w3schools.com/dhtml/default.asp

Also, there is AJAX (async. java). I haven't used it but basically it seems that the page calls the server through java script and refreshes only a portion of the page without having to reload the entire page.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.