I have a simple formatDate function written in javascript as seen below.
I'm trying to add an onchange property to my textbox so it will format the date after the user types in a value so I have added this line to my codebehind file as follow:
When I step through the javascript it returns the correct format but it does not update my textbox at all.
Any tips or suggestions be greatly appreciated.
Code:
<script language="javascript">
function formatDate(str, style) {
var dateVar = new Date(str);
var year = dateVar.getYear();
if(year<10)
year += 2000;
if(year<100)
year += 1900;
switch(style) {
case "MM/DD/YY":
return ((dateVar.getMonth() + 1) + "/" + dateVar.getDate() + "/" + year);
break;
}
}
I'm trying to add an onchange property to my textbox so it will format the date after the user types in a value so I have added this line to my codebehind file as follow:
Code:
calfield1.Attributes.Add("onchange","formatDate(this.value, 'MM/DD/YY')");
When I step through the javascript it returns the correct format but it does not update my textbox at all.
Any tips or suggestions be greatly appreciated.