aaalife
asked on
displaying javascript in label
how can i display datetime logic from javascript into a label on an asp.net page??? i tried the following but the time is displaying in upper left corner, not on the datetimelbl.
thanks
<body>
<span id="tP"> </span>
<script type="text/javascript">
function timeSource(){
x=new Date();
x.setTime(x.getTime());
return x;
}
function leadingZero(x){
return (x>9)?x:'0'+x;
}
function twelveHour(x){
if(x==0){
x=12;
}
return (x>12)?x-=12:x;
}
function dateEnding(x){
if(x==1||x==21||x==31){
return 'st';
}
if(x==2||x==22){
return 'nd';
}
if(x==3||x==23){
return 'rd';
}
return 'th';
}
function displayTime(){
window.status=''+eval(outp utTime)+'' ;
document.title=''+eval(out putTime)+' ';
document.getElementById('t P').innerH TML=eval(o utputTime) ;
setTimeout('displayTime()' ,1000);
}
function amPMsymbol(x){
return (x>11)?'pm':'am';
}
function fixYear4(x){
return (x<500)?x+1900:x;
}
var dayNames=new Array('Sunday','Monday','T uesday','W ednesday', 'Thursday' ,'Friday', 'Saturday' );
var monthNames=new Array('January','February' ,'March',' April','Ma y','June', 'July','Au gust','Sep tember','O ctober','N ovember',' December') ;
var outputTime="dayNames[timeS ource().ge tDay()]+' '+monthNames[timeSource(). getMonth() ]+' '+timeSource().getDate()+d ateEnding( timeSource ().getDate ())+' '+fixYear4(timeSource().ge tYear())+' '+':'+':'+' '+twelveHour(timeSource(). getHours() )+':'+lead ingZero(ti meSource() .getMinute s())+':'+l eadingZero (timeSourc e().getSec onds())+' '+amPMsymbol(timeSource(). getHours() )";
if(!document.all){ window.onload=displayTime; }else{ displayTime(); }
document.getElementById("< %= datetimelbl.ClientID %>").innerText = displayTime();
</script>
<form id="form1" runat="server">
<div>
<asp:Label ID="datetimelbl" runat="server" Style="z-index: 122; left: 707px; position: absolute;
top: 24px" Text="Label" Width="267px">
</asp:Label>
thanks
<body>
<span id="tP"> </span>
<script type="text/javascript">
function timeSource(){
x=new Date();
x.setTime(x.getTime());
return x;
}
function leadingZero(x){
return (x>9)?x:'0'+x;
}
function twelveHour(x){
if(x==0){
x=12;
}
return (x>12)?x-=12:x;
}
function dateEnding(x){
if(x==1||x==21||x==31){
return 'st';
}
if(x==2||x==22){
return 'nd';
}
if(x==3||x==23){
return 'rd';
}
return 'th';
}
function displayTime(){
window.status=''+eval(outp
document.title=''+eval(out
document.getElementById('t
setTimeout('displayTime()'
}
function amPMsymbol(x){
return (x>11)?'pm':'am';
}
function fixYear4(x){
return (x<500)?x+1900:x;
}
var dayNames=new Array('Sunday','Monday','T
var monthNames=new Array('January','February'
var outputTime="dayNames[timeS
if(!document.all){ window.onload=displayTime;
document.getElementById("<
</script>
<form id="form1" runat="server">
<div>
<asp:Label ID="datetimelbl" runat="server" Style="z-index: 122; left: 707px; position: absolute;
top: 24px" Text="Label" Width="267px">
</asp:Label>
ASKER
no help, time still not displaying in label
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var x = document.getElementById('d atetimelbl ');
try one of these two:
x.text = displayTime();
x.value = displayTime();
try one of these two:
x.text = displayTime();
x.value = displayTime();
ASKER
neither of the above solutions worked, still getting time in upper left, not in label.
what are you trying to do? are you trying to use a calendar to select a date and put the selected date into a label?
ASKER
I'm trying to display the current date time from javascript in an asp.net label control.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
once i moved script below the label in the body, everything worked fine. i guess the getelementid needed to already have the label created before finding it. i moved the code above the label declaration and nothing, with script below, label shows javascript output.
document.getElementById("<