Link to home
Create AccountLog in
JavaScript

JavaScript

--

Questions

--

Followers

Top Experts

Avatar of Manju
Manju🇮🇳

Classic ASP - Count down timer from 10 seconds to 0 with text changing
Experts -

I need a countdown timer in classic asp from 10 seconds to 0. (Without page refresh)

Ex:
In a DIV  (<p>)- I will need to say "Kindly allow 10 seconds for Request creation..., " Here the 10 should count down to 0. and Once it becomes 0, it should change the <p> text to "Request created".

I understand there are alot of timers available in js/jquery but my ask is unique and peculiar and i dont want the page / body to refresh every 10 seconds or so.

Kindly help.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Chinmay PatelChinmay Patel🇮🇳

Hi Manju,

This counter has to be controlled from server? or it should actually wait for the actual request creation and then set the text to Request Created?

Regards,
Chinmay.

Avatar of ManjuManju🇮🇳

ASKER

no, just a 10 second wait is good enough. basically, below is what i need.

<div><p>Kindly allow 10 seconds for Request creation..., </p></div> ("Note: count down from 10 to 0 should show )
once it hits 0,
<div><p>Request created. </p></div>

ASKER CERTIFIED SOLUTION
Avatar of Chinmay PatelChinmay Patel🇮🇳

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Scott FellScott Fell🇺🇸

That can't be done in asp or any server side script.  you need to do it in javascript (or jquery other js framework).

I think what you want to do is an ajax call where you submit the form on page1.asp where the page does not refresh. The ajax call hits the processing.asp page. When the processing asp page is done, then page1.asp updates without the refresh.  You can have a timer or other moving something hit that div while the processing page is doing it's thing.

If you do use serverside scripting to do a count down, you are tying up the cpu.  Enough users doing that and you can take down the app pool.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Scott FellScott Fell🇺🇸

The js code for ajax using jquery is going to be


<div id="results"></div>
<form>
   <input id="field1">
   <input id="field2">
   <button id="button1">submit</button>
</form>

Open in new window

$(function(){  // START AT PAGE LOAD

   $('#button1').on('click',function(){ //LIST FOR BUTTON CLICK
    $('#results').html('we are working on it');  // OR USE A TIMER OR SPINNER PNG/GIF
    

     var field1 = $('#field1').val();
     var field2 = $('#field2').val();


       $.ajax({
       method: "POST",
       url: "processing.asp",
       data: { field1: field1, field2: field2 }
       })
      .done(function( data ) {  // data IS WHAT WILL BE RETURNED FROM THE PROCESSING.ASP PAGE
         $('#results').html(data); 
      });


   });


});

Open in new window

PROCESSING.ASP
field1=request.form("field1")
field2 = request.form("field2")

' simulate a resposne
response.write "Field 1 = "&field1&" Field 2 = "&field2

Open in new window


Avatar of ManjuManju🇮🇳

ASKER

Thank you

Avatar of Scott FellScott Fell🇺🇸

While the pure javascript timer does what you asked, counts down, I don't believe this is an optimal solution for what you are trying to achieve.

The reason is it appears you are waiting for a process to finish.  The solution selected can act like a jack-in-the-box. When the timer is up, you have no idea what you are getting.  It could be something good like the process is finished or it could be an error or the process is still going.  The optimal way to do wait for page to process is to use ajax. This allows the exact time to show a counter, spinner or anything that something is being processed.  When the page is done, you can capture the output of the process page and disseminate for your user.  If the process is taking too long, you can add something to your ajax to account for this as well such as offering a way to report an issue.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.

JavaScript

JavaScript

--

Questions

--

Followers

Top Experts

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.