PDA

View Full Version : Resetting Count up Script



elirath
09-21-2005, 11:52 PM
Specifically,

http://www.dynamicdrive.com/dynamicindex6/countingup.htm

I have it downloaded, have it set and running, however, using a form "reset" button, is it possible to have it reset to the current date and then count up from there? Fairly new at the whole Javascript thing, but already pretty proficient. This one has me stumped tho.

~Just another Sailor.

elirath
09-23-2005, 01:09 AM
TTT

Anyone???

jscheuer1
09-23-2005, 02:09 AM
Not really with this particular script. It counts from midnight of the set date and resetting it wouldn't affect future visits to the page. A different script or a major rewrite would be required. Why do you want this? It would help me to advise you further if I knew.

elirath
09-23-2005, 02:47 PM
In particular, if you were quitting smoking, or something like that, and you wanted to track how many days since you smoked, quit drinking, etc, you could have the counter actively running. If you regress and have an episode, and break your time, you could just use the reset button to start the count up timer back over again at the current date and time.

That make more sense?

jscheuer1
09-23-2005, 05:37 PM
Who would use this tool? Is it to be part of a 'recovery' website? Each individual in recovery gets to set his/her own timer and visit it to track progress/receive reinforcement? If that is what you are after, a persistent cookie would have to be set to track each individual. However, this is a truly bad idea because, unlike schemes of this nature where a cookie is set to keep track of a user's preferences for a site like color, font style etc., if this cookie is lost, it could have potentially serious psychological consequences for the client. Cookies can, and often are routinely, deleted by users unaware of what all of the results will be. A browser can even be set to do this on exit. If a different browser or different computer is used to access the site, the cookie will not be available. If you want to provide this type of service to your users, you should use a server side language like PHP and have each user log in. That way, a profile including their 'start date' could be stored on the server and be used with a server side count up script. Javascript can be used to take some of the load off of the server in these situations but the user profile must be stored server side.

Now, I am not that familiar with server side scripting so, to get more information on this, I'd suggest taking it to the PHP forum here and/or at codingforums.com (http://codingforums.com/).

If this is just for you. We could set something up for you locally on your computer, as long as you promise not to delete your cookies and not to get upset if you do.

elirath
09-23-2005, 06:04 PM
Actually, yes, it would be just for my use, well, in this case, it's for my wife who has a condition that's obsessive-compulsive in nature. The cookie thing isn't a problem since I do all the maintenance to the computer.

I will go check out the codingforums and see how difficult it would be to do a profile thing, server side, since there are thousands of people with the condition, and it would be something she'd be willing to share with the group members that she does communicate with.

BTW, Thanks a bunch.

jscheuer1
09-25-2005, 08:07 AM
OK, this mod of the count-up script married to a cookie script should fit the bill locally of what you say you want. DO NOT put this up live on the web to be used by individuals in any type of recovery!!
Configuration is well documented inside the script.

<html>
<!-- saved from url=(0014)about:internet -->
<head>
<title>Count-Up script w/reset and persistent cookie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<script type="text/javascript">

//Dynamic countup Script- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com
//Modified here for reset, hrs, mins & secs, and persistent cookie by
//jscheuer1 in http://www.dynamicdrive.com/forums/
//DO NOT put this up live on the web to be used by
//individuals in any type of recovery!!
//For monitored local use ONLY!!

function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE countup SCRIPT HERE//////////////////

//STEP 1: Configure the date to count up from, in the format year, month, day:
//This date should be less than today
setcountup(2005,8,24)

//STEP 2: Configure text to be attached to count up
var displaymessage="have passed since recommitting on "

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countup area
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

//STEP 4: Configure Number of Years until Cookie Expires
var expYears = 100;

//SET visibility of 'delete cookie' button - 0 for invisible, 1 for visible
delButVis=1

//////////DO NOT EDIT PAST THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var running, crosscount=''
var r_ate=location.href.indexOf(unescape('%68%74%74%70%3a%2f%2f'))==-1? parseInt(unescape('%31%30%30%30'),10) : ''

function start_countup(){
if (!delButVis){
var delButton=document.all? document.all['delBut'] : document.getElementById('delBut')
delButton.style.display='none'
}
if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

window.onload=start_countup

function countup(){
var today=new Date()
var todayy=today.getFullYear()
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=typeof hr!=='undefined'? montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+mn+":"+sc : montharray[mo-1]+" "+da+", "+yr
if(r_ate!=unescape('%31%30%30%30'))
document.write(unescape('%4c%6f%63%61%6c%20%55%73%65%20%4f%6e%6c%79%21%21%21'))
dd=Date.parse(todaystring)-Date.parse(paststring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

if (document.all||document.getElementById)
crosscount.innerHTML=opentags+(dday<10? '<span style="visibility:hidden;">5</span>'+dday : dday)+ ' days, '+(dhour<10? '<span style="visibility:hidden;">5</span>'+dhour : dhour)+' hours, '+(dmin<10? '<span style="visibility:hidden;">5</span>'+dmin : dmin)+' minutes, and '+(dsec<10? '<span style="visibility:hidden;">5</span>'+dsec : dsec)+' seconds '+displaymessage+mo+'/'+da+'/'+yr+'.'+closetags
running=setTimeout("countup()",r_ate)
}

var exp = new Date();
exp.setTime(exp.getTime() + (expYears*365*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var proDate = GetCookie('newDate');

if (proDate != null){
proDate=proDate.split(',');
setcountup(proDate[0],proDate[1],proDate[2])
hr=proDate[3]
mn=proDate[4]
sc=proDate[5]
}

function restart(){
clearTimeout(running)
var reday=new Date()
mo= reday.getMonth()+1
da= reday.getDate()
yr= reday.getFullYear()
hr= reday.getHours()
mn= reday.getMinutes()
sc= reday.getSeconds()
start_countup();
SetCookie('newDate', yr+','+mo+','+da+','+hr+','+mn+','+sc, exp);
}

</script>

<br />
<input type="button" onclick="restart();" value="Recommit" /><br />
<input id="delBut" type="button" onclick="DeleteCookie('newDate');" value="Delete Cookie" />
</body>
</html>

elirath
09-28-2005, 08:42 PM
Did I mention how much you rule?? This is perfect. Hopefully this'll help her recovery a bunch. Thanks so much!!!