javascript - Validation for Birth Date, Joining Date and Leaving Date -
i have 3 textboxes birthdate
, joiningdate
& leavingdate
.
what trying ensure is:
joining date
,leaving date
should not greaterbirthdate
leaving date
should not greaterjoining date
,birthdate
.
i throw error when wrong entry has been entered.
i have used datepicker date input user.
here js code using:-
$(function () { $("[id$=maincontent_txtdateofbirth], [id$=maincontent_txtdoj], [id$=maincontent_txtdol]").datepicker({ textboximageonly: true, textboximage: 'images/calendar.png', changemonth: true, changeyear: true, dateformat: "yy / mm / dd", yearrange: "-40:+0", maxdate: new date(), }); });
the textboxes code using:-
<asp:textbox id="txtdateofbirth" cssclass="form-control" runat="server" validationgroup="addnew"></asp:textbox> <asp:textbox id="txtdoj" cssclass="form-control" runat="server" validationgroup="addnew"></asp:textbox> <asp:textbox id="txtdol" cssclass="form-control" runat="server" validationgroup="addnew"></asp:textbox>
i got solution here, not button click attempting do.
here related code:-
tr> <td style="vertical-align: top;"> <label class="control-label" for="dob">date of birth</label></td> <td> <div class="control-group"> <div class="controls"> <asp:textbox id="txtdateofbirth" cssclass="form-control" autocomplete="off" runat="server" validationgroup="addnew"></asp:textbox> <asp:requiredfieldvalidator id="reqdob" runat="server" cssclass="error-class" controltovalidate="txtdateofbirth" errormessage="please select date of birth" validationgroup="addnew"></asp:requiredfieldvalidator> </div> </div> </td> </tr> <tr> <td style="vertical-align: top;"> <label class="control-label" for="subject">date of join</label></td> <td> <div class="control-group"> <div class="controls"> <asp:textbox id="txtdoj" wrap="true" cssclass="form-control" autocomplete="off" runat="server" validationgroup="addnew"></asp:textbox> <asp:requiredfieldvalidator id="reqdoj" cssclass="error-class" runat="server" controltovalidate="txtdoj" errormessage="please add date of joining" validationgroup="addnew"></asp:requiredfieldvalidator> </div> </div> </td> </tr> <tr> <td style="vertical-align: top;"> <label class="control-label" for="subject">date of leaving</label></td> <td> <div class="control-group"> <div class="controls"> <asp:textbox id="txtdol" cssclass="form-control" autocomplete="off" runat="server" validationgroup="addnew"></asp:textbox> </div> </div> </td> </tr><asp:button id="btnsubmit" runat="server" cssclass="btn btn-prm" text="submit" width="75" causesvalidation="true" validationgroup="addnew" onclick="btnsubmit_click" />
please suggest how can validate these dates based on criteria listed above.
edit 2 comments you've posted seems may more difficult put pieces anticipated here need in order result want:
- wire event on server side button click
- within function assign values of datepickers 3 separate variables
- using example code below c#, compare
leavedate
,joindate
birthdate
, determine ifleavedate
,joindate
occur before or afterbirthdate
- continue whatever else application does
edit: here msdn article on how wire button click. if put pieces desired result of validating dates on button click.
comparing dates, in way want relatively straightforward.
to server-side (in c#), here msdn article , example:
using system; public class example { public static void main() { datetime date1 = new datetime(2009, 8, 1, 0, 0, 0); datetime date2 = new datetime(2009, 8, 1, 12, 0, 0); int result = datetime.compare(date1, date2); string relationship; if (result < 0) relationship = "is earlier than"; else if (result == 0) relationship = "is same time as"; else relationship = "is later than"; console.writeline("{0} {1} {2}", date1, relationship, date2); } } // example displays following output: // 8/1/2009 12:00:00 earlier 8/1/2009 12:00:00 pm
to client-side (in javascript), here a, here w3schools article , example:
var today, someday, text; today = new date(); someday = new date(); someday.setfullyear(2100, 0, 14); if (someday > today) { text = "today before january 14, 2100."; } else { text = "today after january 14, 2100."; } document.getelementbyid("demo").innerhtml = text;
Comments
Post a Comment