| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#46
|
||||
|
||||
|
just change the code to this:
Code:
print "<script>ActivateCountDown('".$span_id."','CountDownEnded_".$span_id."',".$time.");</script>";
then add this line: Code:
print "<script>CountDownEnded_".$span_id."() { PostBack('".$span_id."'); }</script>";
I hope my syntax is correct, I'm don't really know PHP. ![]() this will hopefully add proper callback function for each timer, calling the PostBack function with the proper "span_id" value that you can then pass on. |
|
#47
|
|||
|
|||
|
Confused...
Quote:
So I add both lines you show? Or just the second one? |
|
#48
|
||||
|
||||
|
you change your first line to be the first line I gave, and you add the second line
to be right below the first line. try to understand the logic behind it and you'll get much more clear idea. ![]() |
|
#49
|
|||
|
|||
|
Quote:
Working on it... Having trouble getting the second line to work: Code:
print "<script>CountDownEnded_".$span_id."() { PostBack('".$span_id."'); }</script>";
when I echo it, it looks right...but does not open the function. This is basically creating the function CountDownEnded_? on the fly right? I have the Postback function included as well. I put an alert just inside the Postback and am not getting an alert when the countdown ends. Thank You so much for your help!! |
|
#50
|
||||
|
||||
|
oops.. my bad.
![]() should be: Code:
print "<script>function CountDownEnded_".$span_id."() { PostBack('".$span_id."'); }</script>";
you need to create the function rather than call it. my timer code will call it automatically. |
|
#51
|
|||
|
|||
|
Hello Shadow Wizzard, I've returned...appologies for the delay I had to work.
Making good progress! Countdown is running and upon end calls the CountDownEnded_??() function, but does not call the PostBack() function. I placed an alert() inside the CountDownEnded_() and I get the alert, but never get into PostBack. Here is the output from viewing page source: Code:
<script>ActivateCountDown('grn_span68','CountDownEnded_grn _span68',357);
function CountDownEnded_grn_span68()
{ alert('post'); PostBack('68');
}
</script>
and here is PostBack() code: Code:
function PostBack(strNum)
{
alert("post back started");
var objForm = document.createElement("form");
objForm.action = "timesup.php";
objForm.appendChild(CreateHiddenInput("det", "true");
objForm.appendChild(CreateHiddenInput("gnum", strNum);
document.body.appendChild(objForm);
objForm.submit();
}
function CreateHiddenInput(sName, sValue)
{
var objInput = document.createElement("input");
objInput.type = "hidden";
objInput.name = sName;
objInput.value = sValue;
return objInput;
}
I have tried including the PostBack() functions on the same page, in the AdvancedCountDown.js, and in a separate postback.js...does the placement of these functions matter? ie. do they need to be before or after the CountDownEnded_()? Thanks Again! Harv |
|
#52
|
|||
|
|||
|
Thanks to your advice, code, and logic I now have it working!! I abandoned the PostBack() function and went with this:
Code:
echo "<script>ActivateCountDown('".$span_id."', '".CountDownEnded_.$span_id."',".$time.");";
echo "function CountDownEnded_".$span_id."()";
echo " {document.location = \"timesup.php?det=true&gnum=".$row_rsActive['g_number']."\";";
echo " }";
echo "</script>";
and the resulting output is: Code:
<script>
ActivateCountDown('grn_span69','CountDownEnded_grn _span69',586);
function CountDownEnded_grn_span69()
{ document.location = "timesup.php?det=true&gnum=69";
}
</script>
THANK YOU! Your script is beautiful and the time you spent helping me through it is invaluable! Thanks Again! Harv Last edited by Howie50 : December 4th, 2008 at 09:34 AM. Reason: spelling errors |
|
#53
|
||||
|
||||
|
cheers Harv and thanks for the kind words!
![]() I can't understand why it didn't work with "external" function but I guess that if you have it working now it's best if you don't change it anymore. I'm really glad you found this useful and that I was able to help - if you have any further questions or problems, don't hesitate to ask.. ![]() |
|
#54
|
|||
|
|||
|
Quote:
Hi Shadow Wizard ! Thanks for your suggestion, but I have some error about this, I use that TIMER at asp.net C# This's my code: Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Timer Test</title>
<script type="text/javascript" src="CountDown.js"></script>
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", <%=(600 - Abs(DateDiff("s", Now, Session["TimeQuizBegin"])))%>);
}
</script>
<style type="text/css">
#CountDownPanel {color: blue; background-color: yellow; font-size: 18px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello!<br />
Time remaining: <span id="CountDownPanel"></span>
</div>
</form>
</body>
</html>
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["TimeQuizBegin"] = Now;
}
}
I don't know, How implements "Now" variable above because I new here And there are an error message about Abs and DateDiff "The name 'Abs' does not exist in the current context" Please help me..! Thanks a lot |
|
#55
|
||||
|
||||
|
The code I gave back then was for classic ASP using VBScript, it won't
work for you because you're using ASP.NET with C#. you need whole different approach. in the Page_Load method, have this code: Code:
if (Session["TimeQuizBegin"] == null)
{
Session["TimeQuizBegin"] = DateTime.Now;
}
DateTime dtQuizBegin = (DateTime)Session["TimeQuizBegin"];
int nSecDiff = (DateTime.Now - dtQuizBegin).TotalSeconds;
string strJS = string.Format("var _countDownInitialValue = {0}; ", (600 - nSecDiff));
this.ClientScript.RegisterClientScriptBlock( this.GetType(), "countdown_script", strJS, true);
and in the client side JS code have this: Code:
ActivateCountDown("CountDownPanel", _countDownInitialValue);
let me know if something is not working or is not clear enough. ![]() |
|
#56
|
|||
|
|||
|
hey mate im a beginner at ASP and only just started glimpsing at javascript, i understand your reply and starting it with a session to hold its value to one user. How would i set this timer for everone to to viewing the same time and everyone gets the same action after it expires. do i use the aplication method in ASP? if so how would i do it i havent had anything to do with aplications yet.
|
|
#57
|
||||
|
||||
|
Quote:
use the time difference between that date and the current date. to do that, first add or edit file called "global.asa" in the web site root folder. in that file, have such code: Code:
<script language="vbscript" runat="server">
Sub Application_OnStart()
Application("CountDownDate") = #20/11/2010#
End Sub
</script>
this will initialize application variable with some future date, put in there whatever date you like. now the next step is changing the code from this: Code:
ActivateCountDown("CountDownPanel", 100);
to this: Code:
ActivateCountDown("CountDownPanel", <%=DateDiff("s", Now(), Application("CountDownDate"))%>);
that's it, now all users will see the same count down time and it won't "reset". if you have "far" date and need to show days, use the AdvancedCountDown options and follow this thread to learn how to use it. |
|
#58
|
|||
|
|||
|
thanks alot man, apreciate ur help. now ill just figure out how to input data into my globel asa witch shouldent be to hard and go from there. now also im using a free asp host and it has no global file should i just add it to my main directory and it will work? also if u have any nice hosts u know of for free hit me up ;], thanks
|
|
#59
|
||||
|
||||
|
if you don't have global.asa then just have this line in your existing ASP code:
Code:
Application("CountDownDate") = #20/11/2010#
global.asa way is just elegant, not necessity. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Javascript Countdown Timer |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|