<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <script>
        function adddate()
        {
            date=new Date();
            var month = date.getMonth()+1;
             var day = date.getDate();
             var year = date.getFullYear();
             if (document.getElementById('datetext').innertext =='')
             {

             document.getElementById('datetext').innertext = month + ' ' + day + ',' + year;

            }
        }
    </script>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>


    <body onload="adddate();">

    <label id="datetext"></label> 
<%--<input type="text" id="datetext">--%>
    </body>
</html>

<%--this code is working for text box but not for label..why?--%>

Recommended Answers

All 3 Replies

try 'innerHTML' instead of 'innertext'..
.
.
and BTW you should've rather posted this in javascript forum, isn't it?

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html> <script> function adddate() { date=new Date(); var month = date.getMonth()+1; var day = date.getDate(); var year = date.getFullYear(); if (document.getElementById('datetext').innertext =='') { document.getElementById('datetext').innertext = month + ' ' + day + ',' + year; } } </script> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body onload="adddate();"> <label id="datetext"></label> <%--<input type="text" id="datetext">--%> </body></html>

thanks its working..sorry by mistake posted here.

If you got it working then plz mark the thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.