mckeegan375 Posted October 14, 2011 Share Posted October 14, 2011 Hi All Was hoping someone could help me with a little validation problem. On my webpage, i have a form which has two date fields which are made of 3 drop down boxes each (DD, MM and YYYY). I am trying to make it so that a javascript message alert appears if the start date entered is before the end date but im not sure how to do it. Is there a way i can take my 3 date dropdown values and turn them into some kind of date string so that i can them go on to say if startdate > enddate then display the alert box? Any help would be greatly appreciated as i have little knowledge of javascript. Cheers Andy Quote Link to comment https://forums.phpfreaks.com/topic/249137-javascript-validation-problem/ Share on other sites More sharing options...
requinix Posted October 14, 2011 Share Posted October 14, 2011 You could just compare the parts: if (start year > end year || start year == end year && start month > end month || start year == end year && start month == end month && start day > end day) { // start > end } Quote Link to comment https://forums.phpfreaks.com/topic/249137-javascript-validation-problem/#findComment-1279419 Share on other sites More sharing options...
nogray Posted October 14, 2011 Share Posted October 14, 2011 Create new date for each set (var st_dt = new Date(Year, Month, Date); // Month starts from 0 for Jan) and compare the times ( st_dt.getTime() < end_dt.getTime()) Quote Link to comment https://forums.phpfreaks.com/topic/249137-javascript-validation-problem/#findComment-1279447 Share on other sites More sharing options...
mckeegan375 Posted October 14, 2011 Author Share Posted October 14, 2011 Thanks for the help guys, i used requinix's solution in the end. Cheers Andy Quote Link to comment https://forums.phpfreaks.com/topic/249137-javascript-validation-problem/#findComment-1279478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.