/    Sign up×
Community /Pin to ProfileBookmark

thanx for u r help…this problem is get solved..

my next problem is that there is two input text field named due_date1 and due_date2..

The due_date2 will always be greater than due_date1..and the format will be dd/mm/yyyy.

if the user enter greater date in due_date1..it displays error and clear the field.

there will be no restriction of any present..past and future dates..it simply accepts date in dd/mm/yyyy format.

below script is working..but the problem is that it doesnot accept future date.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
http://www.w3.org/TR/html4/strict.dtd“>
<html lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<meta name=”Content-Script-Type” content=”text/javascript”>
<meta name=”Content-Style-Type” content=”text/css”>
<title>Example</title>

<script type=”text/javascript”>
<!–
Date.prototype.toDDMMYYYYString = function () {return isNaN (this) ? ‘NaN’ : [this.getDate() > 9 ? this.getDate() : ‘0’ + this.getDate(), this.getMonth() > 8 ? this.getMonth() + 1 : ‘0’ + (this.getMonth() + 1), this.getFullYear()].join(‘/’)}

Date.fromDDMMYYYY = function (s) {return (/^(dd?)D(dd?)D(d{4})$/).test(s) ? new Date(RegExp.$3, RegExp.$2 – 1, RegExp.$1) : new Date (s)}

String.prototype.isDate = function () {return this == Date.fromDDMMYYYY(this).toDDMMYYYYString()}
// –>
</script>

<style type=”text/css”>
<!–
fieldset {padding:1ex; width:10em}
label {display:block; margin:1em 0}
input {display:block}
button {display:block; margin:auto}
–>
</style>

</head>
<body>
<form action=”some-script.pl”>
<fieldset>
<legend>Example</legend>

<label>Some date in the past <input name=”past” type=”text” onchange=”if (!this.value.isDate()) {alert(); this.value = ”; this.focus()} else if (Date.fromDDMMYYYY(this.value) > new Date()) {alert(); this.value = ”; this.focus()}”></label>

<label>Some date after that <input name=”later” type=”text” onchange=”if (!this.value.isDate()) {alert(); this.value = ”; this.focus()} else if (Date.fromDDMMYYYY(this.value) < Date.fromDDMMYYYY(this.form.past.value)) {alert(); this.value = ”; this.focus()}”></label>

<button type=”submit”>Submit</button>
</body>
</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @abhit_kumar 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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