alexisbr
asked on
How to alternate between 2 messages until page closes in Classic ASP
Hi. I am maintaining an old system written in Classic ASP with a SQL Server 2012 backend.
There currently is a message displayed on the home page. Now I need to alternate between 2 messages on the page every 4 seconds until the page is closed. I checked the web and discovered there is no sleep or pause function in classic asp as exists in other languages. The home page I am changing already has a video displaying when it opens so I don't want slow it down more.
I'm trying to work with a simple example. If i can get this to work then maybe i could apply it to my more complicated page.
I can't figure out how to write the code so the 2 messages display on the same row on the page and switch off every 4 seconds until the page is closed. My example displays the messages one after the other and that's it.
Does anyone have any suggestions?
Thank you for your help.
Regards,
Alexis
There currently is a message displayed on the home page. Now I need to alternate between 2 messages on the page every 4 seconds until the page is closed. I checked the web and discovered there is no sleep or pause function in classic asp as exists in other languages. The home page I am changing already has a video displaying when it opens so I don't want slow it down more.
I'm trying to work with a simple example. If i can get this to work then maybe i could apply it to my more complicated page.
I can't figure out how to write the code so the 2 messages display on the same row on the page and switch off every 4 seconds until the page is closed. My example displays the messages one after the other and that's it.
<%
dim message1, message2
message1 = "hello"
message2 = "hello 2"
response.Write message1 & "<br><br>"
response.Write message2
%>
Does anyone have any suggestions?
Thank you for your help.
Regards,
Alexis
Even if there was such a function in Classic ASP, it wouldn't do you any good because by the time the page is displayed, the ASP code has finished running. There are timer functions in JavaScript that you can use to do that. Look at The setInterval() Method on this page: http://www.w3schools.com/js/js_timing.asp
ASKER
Thank you, Dave. It's been a long time since I've done anything in Javascript and I am struggling with this.
I've been playing with the code from the link you sent and other posts I found on javascript functions.
Here's what I have so far. I am passing my 2 message values from ASP to the function with the javascript.
With the code as you see it below, I see the first message "hello" but not the second one. If I uncomment the first clearinterval line, I see the second message but not the first. I cannot figure out how to alternate between the 2 messages every 4 seconds.
Can you please offer any suggestions?
Thanks,
Alexis
I've been playing with the code from the link you sent and other posts I found on javascript functions.
Here's what I have so far. I am passing my 2 message values from ASP to the function with the javascript.
With the code as you see it below, I see the first message "hello" but not the second one. If I uncomment the first clearinterval line, I see the second message but not the first. I cannot figure out how to alternate between the 2 messages every 4 seconds.
<%
dim message1, message2
message1 = "hello"
message2 = "hello 2"
call functiontest()
function functiontest()
%>
<script language="javascript">
var myVar = setInterval(myTimer, 4000);
// clearInterval(myVar);
function myTimer() {
document.write('<%=message1%>');
}
var myVar2 = setInterval(myTimer2, 8000);
// clearInterval(myVar2);
function myTimer2() {
document.write('<%=message2%>');
}
// document.write("hello test");
</script>
<%
end function
%>
Can you please offer any suggestions?
Thanks,
Alexis
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, Dave. This is exactly what I hoped to accomplish. I would not have thought to arrange the code in this way. I am going to apply it to my real page now.
Regards,
Alexis
Regards,
Alexis
ASKER
Hi again Dave,
I was able to incorporate this code into my asp page. Thank you again for all your help. I really appreciate it.
Regards,
Alexis
I was able to incorporate this code into my asp page. Thank you again for all your help. I really appreciate it.
Regards,
Alexis
ASKER
Awesome solution!
You're welcome, glad to help.