tags:

views:

54

answers:

3
<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());
    }
}
+1  A: 

If you want to populate it as soon as page loads, you can use the load event eg:

window.onload = function(){
  addDefaultDate();
};
Sarfraz
+1  A: 

since you're already using jquery i would suggest something like

$(document).ready(function(){ addDefaultDate(); });

nathan gonzalez
hmm yes and when to call it and how? i do not want to call body onload function.
senzacionale
well, when to call it is entirely up to you i think. the code i posted above will run after the entire page has been loaded, similar to the window.onload function. when would you like to to happen? is there a button click or some other similar event?
nathan gonzalez
thx for helping
senzacionale
+1  A: 

Try this

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