PDA

View Full Version : Local Time script + input type text



lnunesbr
01-22-2007, 03:08 PM
1) Script Title: Local Time script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex6/localtime.htm

3) Describe problem:
How can I put the received time in a form input text and not in a div/span tag.



sorry the bad English...

Thanx for your help!

jscheuer1
01-22-2007, 04:49 PM
Use this modified function in place of the one in the script:


showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long"){
if(this.container.tagName.toLowerCase()=='input')
this.container.value=this.localtime.toLocaleString()
else
this.container.innerHTML=this.localtime.toLocaleString()
}
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
if(this.container.tagName.toLowerCase()=='input')
this.container.value=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
else
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

And, instead of this:


Current Server Time:<span id="timecontainer"></span>

Use this:


Current Server Time:<input type="text" id="timecontainer">

lnunesbr
01-22-2007, 06:41 PM
It worked fine!

Thanks for your help!!!