0

I have two text boxes, one is "From Date" and "To Date". user will enter the date in the format of "mm/dd/yyyy". Here the "To Date" is always Greater than "From Date". if not, i will alert the user "Not valide, To date is always greater than From Date".

Ex: From Date: 06/05/2011 To Date: 05/08/2011

The above statement is wrong.

       Please give your answer.
1

2 Answers 2

1

First, you'll probably want to use <input type="date">, which does some validation on browsers that support it, and shows as a regular input box on browsers that don't.

For actually validating that one date is before the other, you can use a JavaScript Date Object.

var fromDate = new Date(from.value);
if (isNaN(fromDate.getTime())
  alert("Invalid From Date");
var toDate = new Date(end.value);
if (isNaN(toDate.getTime())
  alert("Invalid To Date");
if (toDate < fromDate)
  alert("Not valid, To date is always greater than From Date");
Sign up to request clarification or add additional context in comments.

Comments

0

That's one way to do it. Another might be to ask if the user wishes to reverse the two.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.