Manju
asked on
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.
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.
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>
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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>
$(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);
});
});
});
PROCESSING.ASPfield1=request.form("field1")
field2 = request.form("field2")
' simulate a resposne
response.write "Field 1 = "&field1&" Field 2 = "&field2
ASKER
Thank you
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.
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.
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.