/    Sign up×
Community /Pin to ProfileBookmark

Date greater than another validation

I have a form with a date that is selected then they pick a date to repeat an action to. I need to make sure that the date they are repeating to is always greater than the frist date becuase I do not want to loop and repeat in the past ?

Here is what I tried but I get an alert on everything so I know it is wrong…

one_shiftdate is the repeat until date…and date is the start from date.

[code]

function TheFormCheck()
{
if (document.new_event.one_shiftdate.value != “”)
if (document.new_event.date.value > document.new_event.one_shiftdate.value)
{
alert(“The repeat date must be greater than the selected event date.”);

document.new_event.one_shiftdate.focus();

return false;
}

}

[/code]

Thanks for any help with this

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonJan 06.2006 — What is the format that they are entering the dates in?
Copy linkTweet thisAlerts:
@tripwaterauthorJan 06.2006 — "Y-m-d"

example

2006-1-6
Copy linkTweet thisAlerts:
@balloonbuffoonJan 06.2006 — I've tested the following on FF and IE:
[CODE]function TheFormCheck() {
if (document.new_event.one_shiftdate.value != "") {
var date = document.new_event.date.value
var repeat = document.new_event.one_shiftdate.value
dates = new Array();
dates = date.split("-")
if (dates[1].length == 1) dates[1] = "0" + dates[1]
if (dates[2].length == 1) dates[2] = "0" + dates[2]
date = dates.join("")
repeats = new Array();
repeats = repeat.split("-");
if (repeats[1].length == 1) repeats[1] = "0" + repeats[1]
if (repeats[2].length == 1) repeats[2] = "0" + repeats[2]
repeat = repeats.join("")
if (date >= repeat) {
alert("The repeat date must be greater than the selected event date.");
document.new_event.one_shiftdate.select();
return false;
}
}
}
[/CODE]

You'll need to escape all the quotes again (if you did that for a reason in your code.) Month can either be in the format MM or M and days can be DD or D but year must always be YYYY (unless you'd like the option for them to input YY, in which case I can change the code.)

--Steve
×

Success!

Help @tripwater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...