简体   繁体   中英

How to validate the Two Date fields on my view using jquery or javascript

I have two fileds in my View one is Effective data and one is Cancel date

 <td>
                Effective date:
            </td>
            <td>
                <%= Html.TextBoxFor( x => Model.SelectedAccountGroup.GroupEffectiveDate, new { @class="datepicker"} )%>
                <%= Html.ValidationMessageFor( x => x.SelectedAccountGroup.GroupEffectiveDate )%>
            </td>
        </tr>
        <tr>
            <td>
                Cancel date:
            </td>
            <td>
                <%= Html.TextBoxFor( x => Model.SelectedAccountGroup.GroupCancelDate, new { @class = "datepicker" } )%>
                <%= Html.ValidationMessageFor( x => x.SelectedAccountGroup.GroupCancelDate )%>
            </td>

On Save button I should not allow user to Enter the Cancel date Before Effective data? can any body tell me how to do this?

get the two date field value as a single integer value . For eg 20101006 .

if time is also there add that too,

if you use jquery

var dateval= $("#dateid").val();

for javascript

var dateval = document.getElementById("dateid").value;

I assume the text box where you show date is having an id. let it be dateid

Now you can compare two fields just as integer.

if(date1>date2)

do something

return false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM