It would help to know what the input value is, but in general you need to be aware that there are a number of known cross-browser quirks when working with the built-in Date
object. A string that is successfully parsed as a date in one browser may not be seen as valid in another.
Secondly, testing for "Invalid Date"
is probably not the best way to determine whether the date is valid. I would suggest that if(isNaN(datefrom.getDate()))
is probably going to be a better test.
Finally, if you're parsing date strings, you might want to consider using one of the third-party libraries that are available for making dates easier to work with in JS. Look up either Date.js or Moment.js. These libraries will give you better cross-browser compatibility, and also additional features that aren't in the standard Date object.