0

Possible Duplicate:
How to check 2 date fields and compare to see which date is ahead, behind or the same

I am trying to implement a validation which should compare two dates and give an alert message.

entrydate is a text feild in our ASP page and so is vdata. I should check and make sure that vdata is always greater than or equal to entrydate. The code below is not working.

Please help to identify what the problem is with the this code:

if(document.Step2.entrydate.value <= document.all(vData).value)
Community
  • 1
  • 1
  • This is not the solution, but don't use `document.all`: http://stackoverflow.com/questions/7693542/document-documentelement-vs-document-all – The Nail Feb 24 '12 at 21:39
  • not enough details by far. what does console.log(document.all(vData)) give you? – mindandmedia Feb 24 '12 at 21:40

2 Answers2

2

The problem is that the text in an input box is just that, text. You are trying to compare dates, so you will need to convert those strings into dates and compare the dates.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
0

The problem is that the value of a textfield is a string. So you're basically comparing strings, and not dates.

You would first need to parse your string into an actual Date object before you can do a reliable comparison. How you would do that depends on the format of the data

Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86