Same code is working fine. If there is value for textbox as proper format in date. also if there is no any date then it get value as NaN-NaN-NaN for totalFinal variable.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
window.onload = function () {
var txtFirstTextbox = document.getElementById('<%= txtCurrentDate.ClientID %>');
var fromdate11 = (txtFirstTextbox.value);
var fromdate = new Date(fromdate11);
var dd = fromdate.getDate();
var mm = fromdate.getMonth() + 1; //January is 0!
var yyyy = fromdate.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
var todayFinal = dd + '-' + mm + '-' + yyyy;
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtCurrentDate" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
txtCurrentDate.Text = DateTime.Now.ToShortDateString();
}
}
Be sure the value you are setting for textbox is in proper format of date.