I have another issue that came up due to fixing an issue with Google Chrome. I have a checkbox list that is connected to my database. Whenever the user would hit the BACK button in Google Chrome ONLY the checkboxes that were selected would still be clicked.
I have that issue resolved, but it has caused my 'current time' code to not work and not update every second. Any ideas how to fix this? I might just have to decide to keep either the time feature or go with the code that fixes the google chrome issue.
Code:
var dayarray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")
var montharray = new Array("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
function getthedate() {
var mydate = new Date()
var year = mydate.getYear()
if (year < 1000)
year += 1900
var day = mydate.getDay()
var month = mydate.getMonth()
var daym = mydate.getDate()
if (daym < 10)
daym = "0" + daym
var hours = mydate.getHours()
var minutes = mydate.getMinutes()
var seconds = mydate.getSeconds()
var dn = ""
if (hours >= 12)
dn = "PM"
else
dn = "AM"
if (hours > 12) {
hours = hours - 12
}
if (hours == 0)
hours = 12
if (minutes <= 9)
minutes = "0" + minutes
if (seconds <= 9)
seconds = "0" + seconds
//Hire change font size
//
var cdate = "Current Time: "
+ dayarray[day]
+ ", " + montharray[month] + " " + daym + ", " + year
+ " " + hours + ":" + minutes + ":" + seconds + " " + dn
+ " "
if (document.all)
document.all.clock.innerHTML = cdate
else if (document.getElementById) {
document.getElementById("clock").innerHTML = cdate
}
else {
document.write(cdate)
}
}
if (!document.all && !document.getElementById)
getthedate()
function goforit() {
if (document.all || document.getElementById)
setInterval("getthedate()", 1000)
}
function reset_main() {
// alert('asdf');
document.getElementById("form1").reset();
getthedate();
}
HTML Code:
<body onload="reset_main()" >
Thanks for creating new thread in HTML and JS section. Where do you call the 'current time' method? try resetting only the checkbox then instead of restting whole form:
I figured it out. When I added the code you helped me with, I forgot to call the routine that will set the interval every second. That code was never called, so the time would show up from the start and whenever the form was reset etc.
Changed the below:
function reset_main() {
// alert('asdf');
document.getElementById("form1").reset();
getthedate();
}
TO:
function reset_main(){ // alert('asdf'); document.getElementById("form1").reset();
goforit(); }
Marked as answer by tvb2727 on Feb 24, 2012 05:04 PM
tvb2727
Participant
925 Points
1273 Posts
Current Time process on a webpage
Feb 24, 2012 04:22 PM|LINK
I have another issue that came up due to fixing an issue with Google Chrome. I have a checkbox list that is connected to my database. Whenever the user would hit the BACK button in Google Chrome ONLY the checkboxes that were selected would still be clicked. I have that issue resolved, but it has caused my 'current time' code to not work and not update every second. Any ideas how to fix this? I might just have to decide to keep either the time feature or go with the code that fixes the google chrome issue.
Code:
var dayarray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") var montharray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") function getthedate() { var mydate = new Date() var year = mydate.getYear() if (year < 1000) year += 1900 var day = mydate.getDay() var month = mydate.getMonth() var daym = mydate.getDate() if (daym < 10) daym = "0" + daym var hours = mydate.getHours() var minutes = mydate.getMinutes() var seconds = mydate.getSeconds() var dn = "" if (hours >= 12) dn = "PM" else dn = "AM" if (hours > 12) { hours = hours - 12 } if (hours == 0) hours = 12 if (minutes <= 9) minutes = "0" + minutes if (seconds <= 9) seconds = "0" + seconds //Hire change font size // var cdate = "Current Time: " + dayarray[day] + ", " + montharray[month] + " " + daym + ", " + year + " " + hours + ":" + minutes + ":" + seconds + " " + dn + " " if (document.all) document.all.clock.innerHTML = cdate else if (document.getElementById) { document.getElementById("clock").innerHTML = cdate } else { document.write(cdate) } } if (!document.all && !document.getElementById) getthedate() function goforit() { if (document.all || document.getElementById) setInterval("getthedate()", 1000) } function reset_main() { // alert('asdf'); document.getElementById("form1").reset(); getthedate(); } HTML Code: <body onload="reset_main()" >tvb2727
Participant
925 Points
1273 Posts
Re: Current Time process on a webpage
Feb 24, 2012 04:22 PM|LINK
All the HTML code:
<body onload="reset_main()" > <form id="form1" runat="server" > <span id="clock"></span>tvb2727
Participant
925 Points
1273 Posts
Re: Current Time process on a webpage
Feb 24, 2012 04:23 PM|LINK
The code:
document.getElementById("form1").reset();Is what fixes the google chrome portion in my reset_main routinerajsedhain
Contributor
4181 Points
1041 Posts
Re: Current Time process on a webpage
Feb 24, 2012 04:44 PM|LINK
Thanks for creating new thread in HTML and JS section. Where do you call the 'current time' method? try resetting only the checkbox then instead of restting whole form:
document.getElementById("checkboxList1").reset();Raj Sedhain
tvb2727
Participant
925 Points
1273 Posts
Re: Current Time process on a webpage
Feb 24, 2012 05:03 PM|LINK
I figured it out. When I added the code you helped me with, I forgot to call the routine that will set the interval every second. That code was never called, so the time would show up from the start and whenever the form was reset etc.
Changed the below:
function reset_main() { // alert('asdf'); document.getElementById("form1").reset(); getthedate(); }TO:rajsedhain
Contributor
4181 Points
1041 Posts
Re: Current Time process on a webpage
Feb 24, 2012 05:06 PM|LINK
Glad you solved!!
Raj Sedhain
tvb2727
Participant
925 Points
1273 Posts
Re: Current Time process on a webpage
Feb 24, 2012 05:21 PM|LINK
haha yep! Thanks agian for the help.