locked
display the date in text box using javascript RRS feed

  • Question

  • User2044010418 posted

    Hi,

    I am trying to display the current date during form load using javascript in textbox of the form contains the master page files. but i cant could anybody solve my problem.

    My javascript as:

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile ="~/Application.Master" CodeBehind="Test.aspx.cs" Inherits="Web.Test" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceContent" Runat="Server">
    <script type="text/javascript">
    window.onload = function()
    {
    GetDate();
    };
    function GetDate()
    {
    var dt = new Date();
    var dd;
    var mm;
    var yyyy;
    var date;
    var month;
    dd=dt.getDate();
    mm=dt.getMonth();
    date = (+dd) - (+1);
    month =(+mm) + (+1);
    document.getElementById('txtDate').value = month + '/' + date + '/' + dt.getFullYear();

    }
    </script>
    <div> <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
    </div>

    </asp:Content>

    Thanks and regards
    brite


    thanks and regrds
    brite

    Monday, September 30, 2013 4:43 AM

All replies

  • User578059180 posted
     <script type="text/javascript">
    window.onload = function()
    {
    GetDate();
    };
    function GetDate()
    {
    var dt = new Date();
    var dd;
    var mm;
    var yyyy;
    var date;
    var month;
    dd=dt.getDate();
    mm=dt.getMonth() +1 ;
    document.getElementById('txtDate').value = mm + '/' + dd + '/' + dt.getFullYear();
    
    }
    </script>

    January is 0 , so mm = dt.getMonth()+1

    hope this helps..

    Friday, November 1, 2013 12:56 AM