[SOLVED] With JS add default date on TextBox

Issue

<asp:TextBox ID="txtDate" runat="server" AutoPostBack="true" OnTextChanged="txtDate_TextChanged"></asp:TextBox>

how can with Jquery add default date. I do not know where and when to call this code:

function addDefaultDate() {
    if ($('#txtDate').val().length == 0) {
        var now = new Date();
        $('#txtDate').text(now.getDate() + '.' + now.getMonth() + '.' + now.getYear());
    }
}

Solution

Try this

$(document).ready(function(){ 
   var now = new Date();
   var myDate=(now.getMonth()+1) + '.' + now.getDate() + '.' + now.getFullYear();
   $("#txtDate").val(myDate);
});

Answered By – Amirouche Douda

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *