View Full Version : Function that runs automatically every second

05-03-2007, 04:51 PM
Hi there...

Dont know if this should be in this forum or javascript forum:)

Here's the situation...I have a sql table with a column reminder datetime...suppose I set a reminder for today at 3 pm...once its 3 pm, a popup window should appear saying that I have a reminder...

I am using asp, ajax, sql and javascript...

Any ideas??

05-04-2007, 03:05 PM
It sounds like it should be in the "reinventing the wheel" forum :confused:

But if you're using AJAX then all you need to do is write a JS function that sends an XMLHTTP request for the data, writes it to the page, and then calls itself via a setTimeout().

In which case this is probably better suited to the JS forum.

05-04-2007, 06:51 PM
Thanks for your suggestion Spud...I kinda found a small code that partially does what I was trying...


<body onLoad="something()">

<script language="JavaScript" type="text/javascript">

function something() {
var y = window.setInterval("ReminderAlert();", 2000);


function ReminderAlert()

ajaxpage(Page2.asp?ReturnData=SomethingNEW', 'HIDELATER');
if (Request.Cookies("Match")="yes")

On Page2.asp

<%if request("ReturnData")="SomethingNEW" then
mysql="SELECT * FROM Table1"
Set AllRecords= Con.Execute( mySQL )

do while AllRecords.eof<>true

if AllRecords("Field1")<>now() then


end if



According to the above code, I get to Page2 but am unable to return anything from Page2 to Page1...Besides the code in red does not work....I want to be able to return some value so I know when the alert should popup...anyclues?

05-05-2007, 12:24 AM
Instead of using a cookie, can't you just have an ajax page that periodically asks the asp page for things and then get the asp page to Response.Write anything you need back? (then use responsetext or responsexml in the js to get the return data)

Set the asp page to output xml instead of text/html and the js may be able to parse it easier.

EDIT: However, if you know all the reminders you have at page load time, can't you just make the js show the reminder at that time... you don't need the js to ask the asp if it is the correct time yet ;)

05-07-2007, 04:12 PM
Thanks ghell for your feedback...can you give me some small code to explain what you are suggesting...sorry I am an absolute newbie:(


05-07-2007, 10:20 PM
Well its a javascript question and I'm not as good with javascript as I am with ASP, so I would prefer not to give you a bunch of untested code.

Here is the theory though:

Javascript can tell the time. You don't need to constantly ask an ASP script if there are any current reminders, you should be able to get a list of reminders with their times and simply display a message at the correct time. This would require no AJAX, though you may wish to get the page refreshing every 10 minutes or so, so that any reminders added after the page was loaded still get set off. (If you get the page refreshing rather than use AJAX, you would only need to load the events that will happen before the next refresh)

I'm not sure whether there is a way to get something to simply happen at a specific time in javascript. If there is, use that. If there is not, you will need to do something like use setTimeout to create a delay between the current time and the reminder time. When that goes off, get a delay between that time and the time of the next event (assuming there is a next event), and so on.