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">&nbsp;</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(outputTime)+'';
           document.title=''+eval(outputTime)+'';
           document.getElementById('tP').innerHTML=eval(outputTime);
           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','Tuesday','Wednesday','Thursday','Friday','Saturday');
        var monthNames=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
        var outputTime="dayNames[timeSource().getDay()]+' '+monthNames[timeSource().getMonth()]+' '+timeSource().getDate()+dateEnding(timeSource().getDate())+' '+fixYear4(timeSource().getYear())+' '+':'+':'+' '+twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(timeSource().getSeconds())+' '+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>
aaalifeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elvio Lujan.Net Senior DeveloperCommented:
and what happens if you try:

document.getElementById("<%= datetimelbl.ClientID %>").value= displayTime();
aaalifeAuthor Commented:
no help, time still not displaying in label
Roopesh_7Commented:
give

document.getElementById(" datetimelbl").innerText= displayTime();

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

RainMan82Commented:
var x = document.getElementById('datetimelbl');

try one of these two:

x.text = displayTime();

x.value = displayTime();
aaalifeAuthor Commented:
neither of the above solutions worked, still getting time in upper left, not in label.
deanvanrooyenCommented:
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?
aaalifeAuthor Commented:
I'm trying to display the current date time from javascript in an asp.net label control.
aki4uCommented:
can't you put  document.getElementById('datetimelbl').innerText = document.title; inside displayTime function?
aaalifeAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.