TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
601
1.9k
143.1k
check date with javascript
Apr 9 2021 6:32 AM
I have a javascript to verify dates input and enable a submit button if conditions are met. it is working only if sdate is today. what is wrong?
<div
class
=
"row no-gutters"
onchange=
"checkDate()"
>
<div
class
=
"col-md-2"
>
<label
for
=
"PTWContent.StartDate"
class
=
"form-control badge-primary"
>2. Start Date</label>
<input asp-
for
=
"PTWContent.StartDate"
class
=
"form-control"
id=
"sdate"
/>
<span id=
"msg1"
class
=
"text-danger"
></span>
</div>
<div
class
=
"col-md-2"
>
<label
for
=
"PTWContent.EndDate"
class
=
"form-control badge-primary"
>3. End Date</label>
<input asp-
for
=
"PTWContent.EndDate"
class
=
"form-control"
id=
"edate"
/>
<span id=
"msg2"
class
=
"text-danger"
></span>
</div>
</div>
<div
class
=
"col-md-12 d-flex justify-content-center"
>
<button id=
"btnSubmit"
>Save</button>
</div>
<script>
function checkDate() {
var msg1 =
""
; var msg2 =
""
;
var startDate =
new
Date($(
'#sdate'
).val());
var today =
new
Date();
if
(startDate.toLocaleDateString() > today.toLocaleDateString() || startDate.toLocaleDateString() == today.toLocaleDateString()) {
$(
"#edate"
).attr(
"disabled"
,
false
);
var endDate =
new
Date($(
'#edate'
).val());
if
(startDate.toLocaleDateString() < endDate.toLocaleDateString() || startDate.toLocaleDateString() == endDate.toLocaleDateString()) {
$(
"#btnSubmit"
).attr(
"disabled"
,
false
);
}
else
{
msg2 = msg2 +
"Due Date cannot be before Start Date"
;
$(
"#btnSubmit"
).attr(
"disabled"
,
true
);
}
}
else
{
msg1 = msg1 +
"Start Date cannot be in the past"
;
$(
"#btnSubmit"
).attr(
"disabled"
,
true
);
$(
"#edate"
).attr(
"disabled"
,
true
);
}
$(
"#msg1"
).text(msg1);
$(
"#msg2"
).text(msg2);
}
</script>
Reply
Answers (
3
)
what are task the daily tasks for asp.net mvc C# interne ?
Sweet Alert message in ASP.NET CORE MVC