Click to See Complete Forum and Search --> : Alert box on load


lord__icon
06-12-2003, 12:46 PM
OK
What Im trying to do is have a count down script
show up in alert on load
the script is
<script>
fuction countdown()
{
var before="All CRs should be 0"
var current="Today All Change Reuqest need be to 0"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countdown(yr,m,d){
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
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
if (todaym==5)
fmonth=90-todayd
if (todaym==6)
fmonth=60-todayd
if (todaym==7)
fmonth=29-todayd
if(fmonth==0&&todayh==0&&todaymin==0&&todaysec==1){
alert("All CRs Need To be to Zero")
return
}
else
alert(" Only "+fmonth+ " days, "+todayh+" hours, "+todaymin+" minutes, left until "+before)
return
}}

</script>
I have tryed
<body onLoad="countdown()">
how ever this does not work
also the page that this should happen to is in frames could this affect the on load and how could I go about making this happen thanks

scriptkid
06-12-2003, 12:58 PM
not real sure what this is supposed to be doing, think u can give a better explanation plz

David Harrison
06-12-2003, 01:13 PM
I think he means that he want's a countdown to a certain event to show up inside an alert box but I don't think it can be done.
Once the alert box is opened, I don't think that the contents can be changed.

If I am right and that is what you want, why don't you just show the countdown on the page.

scriptkid
06-12-2003, 01:37 PM
yah im pretty sure it cant be done either unless u make a custom alert box using modalDialog

lord__icon
06-12-2003, 01:44 PM
Ok to explain a little bit more on this
I want the countdown to show up in the alert
so it pops up saying you have 23 days left
I do not what it to continue changing like 5 min 4 min .. exc


I just what on load to pop us saying you have 23 days 14 hours left until blah blah

If this is possible Please let me know if Not I gess I can just post a running countdown on the page it self.
Thanks:)

lord__icon
06-12-2003, 03:49 PM
Can some one look over this again now that I have responded hopfuly there is enough information
thanks

David Harrison
06-12-2003, 03:52 PM
do you realise that you have something like this:

function countdown{

blah blah blah

function countdown{

blah blah blah

}}

<body onload="countdown();">

Charles
06-12-2003, 04:02 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.ONE_DAY = Date.ONE_HOUR * 24;
Date.ONE_WEEK = Date.ONE_DAY * 7;

function TimeUntil (d) {this.time = d.getTime ? d.getTime() : Date.parse(d)}

TimeUntil.prototype.valueOf = function () {return this.time - new Date ().getTime()}

TimeUntil.prototype.toString = function () {
var t = Math.abs(this.valueOf());
var d = Math.floor (t / Date.ONE_DAY);
var h = Math.floor ((t % Date.ONE_DAY) / Date.ONE_HOUR);
var m = Math.floor ((t % Date.ONE_HOUR) / Date.ONE_MINUTE);
var s = Math.floor ((t % Date.ONE_MINUTE) / Date.ONE_SECOND);
return (this.valueOf () < 0 ? '-' : '') + [d, d == 1 ? 'day' : 'days', [h, m < 10 ? '0' + m : m, s < 10 ? '0' + s : s].join(':')].join(' ');
}

onload = function () {alert (new TimeUntil ('1 August 2003 10:00 CDT').toString() + ' until the 2003 Hoover Ball National Championships in West Branch, Iowa.')}
</script>

lord__icon
06-12-2003, 04:02 PM
Thanks charles this should work.

lord__icon
06-12-2003, 04:24 PM
OK
I put charles script in to a new window and it worked fine
but When I put it on the acual page None of the page content comes up could this be a problem with it being in frames

thanks

Charles
06-12-2003, 04:29 PM
Post the URL.

lord__icon
06-12-2003, 04:37 PM
Cant Its Intranet based for a Company i cant release any info on sorry

lord__icon
06-12-2003, 04:49 PM
Figured it out thanks

FYI It was because of the <-- not being cloased in chales's script did not let the rest of the page load


thanks for you help