How to add datepicker in asp.net MVC
<div class="editor-field">
@Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.DOB, new {id = "date-picker",@onchange="getage(this.value);" })
@Html.ValidationMessageFor(model => model.DOB)
</div>
<p id="val"></p>
<script type="text/javascript">
debugger
$(document).ready(function () {
debugger
// This will make every element with the class "date-picker" into a DatePicker element
$('#date-picker').datepicker();
});
function getage(dob) {
debugger
var myyear = dob.substring(6, 10);
var mymonth = dob.substring(0, 2);
var myday = dob.substring(3, 5);
today_date = new Date();
today_year = today_date.getFullYear();
today_month = today_date.getMonth();
today_day = today_date.getDate();
age = today_year - myyear;
if (today_month < (mymonth - 1)) {
age--;
}
if (((mymonth - 1) == today_month) && (today_day < myday)) {
age--;
}
document.getElementById("val").innerHTML = age;
}
</script>
@Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.DOB, new {id = "date-picker",@onchange="getage(this.value);" })
@Html.ValidationMessageFor(model => model.DOB)
</div>
<p id="val"></p>
<script type="text/javascript">
debugger
$(document).ready(function () {
debugger
// This will make every element with the class "date-picker" into a DatePicker element
$('#date-picker').datepicker();
});
function getage(dob) {
debugger
var myyear = dob.substring(6, 10);
var mymonth = dob.substring(0, 2);
var myday = dob.substring(3, 5);
today_date = new Date();
today_year = today_date.getFullYear();
today_month = today_date.getMonth();
today_day = today_date.getDate();
age = today_year - myyear;
if (today_month < (mymonth - 1)) {
age--;
}
if (((mymonth - 1) == today_month) && (today_day < myday)) {
age--;
}
document.getElementById("val").innerHTML = age;
}
</script>
Comments
Post a Comment