/    Sign up×
Community /Pin to ProfileBookmark

adding javascript to date field

I have a basic question but I am a beginner in Java Script.

I have 2 fields which are From Date and To Date and want to add
JavaScript that the From Date can never be greater than the To date,
they can be equal but the From can not be greater.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jalarieDec 02.2003 — First, make sure that your input fields have usable names. No spaces. Maybe:

&nbsp;<input ... name="DateF">

&nbsp;<input ... name="DateT">

Then, add a code to your form tag to set off a function to check the dates when the form is submitted:

&nbsp;<form ... onsubmit="return CheckDates">

Finally, create a JavaScript function to pick up those date, compare them, and return appropriately based on the result:

&nbsp;<script type="text/javascript">

&nbsp;&nbsp;function CheckDates() {

&nbsp;&nbsp;&nbsp;DF=document.forms[0].DateF.value;

&nbsp;&nbsp;&nbsp;DT=document.forms[0].DateT.value;

&nbsp;&nbsp;&nbsp;if (DF > DT) {

&nbsp;&nbsp;&nbsp;&nbsp;return false;

&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;return true;

&nbsp;&nbsp;}

&nbsp;</script>
×

Success!

Help @gelfy 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.16,
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,
)...