Link to home
Start Free TrialLog in
Avatar of alexisbr
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.


<%
dim message1, message2
message1 = "hello"
message2 = "hello 2"

response.Write message1 & "<br><br>"
response.Write message2

 %>

Open in new window

 User generated image
Does anyone have any suggestions?

Thank you for your help.

Regards,
Alexis
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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
Avatar of alexisbr
alexisbr

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.  

<%
 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

%>

Open in new window


Can you please offer any suggestions?

Thanks,
Alexis
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
Awesome solution!
You're welcome, glad to help.