How to set calendar date from javascript
when user enters ddMMyy or ddMMyyyy.I want to convert it into dd/MM/yyyy format. To achieve this i have written a javascript. It works fine but when i focus on textbox again it doesnt show selected date as javascript converted date(i.e it doesnt fire event when i manually change the date of the textbox). How to make calendar control to select the date after calling "ConvertToDate" function?
<script type="text/javascript">
function ConvertToDate(txtCnt) {
try {
txtVal = txtCnt.value;
var dd = txtVal.charAt(0).toString() + txtVal.charAt(1).toString();
var MM = txtVal.charAt(2).toString() + txtVal.charAt(3).toString();
var year = txtVal.substring(4);
if (year.length == 2) year = "20" + year;
var jsDate = new Date();
txtCnt.value = dd + "/" + MM + "/" + year;
} catch (e) {
}
return false;
}
</script>
<asp:TextBox开发者_开发技巧 ID="txtFromDt" runat="server" onblur="return ConvertToDate(this)" Width="80px"></asp:TextBox>
<cc1:CalendarExtender ID="txtFromDt_CalendarExtender" runat="server" CssClass="cal_Theme1"
Format="dd/MM/yyyy" Enabled="True" TargetControlID="txtFromDt" />
As you can call this function on :-- onblur event as it fire when an object loses focus.
精彩评论