/    Sign up×
Community /Pin to ProfileBookmark

Compare two form fields

I have a start time and end time field in a form. What I need is some code that will ensure that end time is at least 8 hours after start time. Thinking would be best to call the script once the user exits the end time field. My JS experience is limited to the few questions I have asked here, so please provide as much detail as possible.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Apr 02.2004 — assuming we are using military time, simply:[code=php]<Script type="text/javascript">

var start = "10:05"
var end = "20:55"

var newStart = start.split(":")
var newEnd = end.split(":")

if((newEnd[0] - 8) >= newStart[0]) {
//good
}
else {
//bad
}

</script>[/code]
work off that ?
×

Success!

Help @betheball 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...