/    Sign up×
Community /Pin to ProfileBookmark

to check to date must be greater or equal from date

Hi All,

I code my date selection like this :

<select name=”day” class=”formData”>
<cfloop index=”d” from=”1″ to=”31″ step=”+1″>
<option value=”#d#” <cfif d eq day(now())>selected</cfif>>#d#</option>
</cfloop>
</select>

<select name=”month” class=”formData”>
<cfloop index=”i” from=”1″ to=”12″ step=”1″>
<option value=”#i#” <cfif i eq month(now())>selected</cfif>>#uCase(monthAsString(i))#</option>
</cfloop>
</select>

<select name=”year” class=”formData”>
<cfloop index=”j” from=”#year(dateAdd(“yyyy”,”-10″,now()))#” to=”#year(dateAdd(“yyyy”,”10″,now()))#” step=”1″>
<option value=”#j#” <cfif j eq year(now())>selected</cfif>>#j#</option>
</cfloop>
</select>

to

<select name=”day2″ class=”formData”>
<cfloop index=”d” from=”1″ to=”31″ step=”+1″>
<option value=”#d#” <cfif d eq day(now())>selected</cfif>>#d#</option>
</cfloop>
</select>

<select name=”month2″ class=”formData”>
<cfloop index=”i” from=”1″ to=”12″ step=”1″>
<option value=”#i#” <cfif i eq month(now())>selected</cfif>>#uCase(monthAsString(i))#</option>
</cfloop>
</select>

<select name=”year2″ class=”formData”>
<cfloop index=”j” from=”#year(dateAdd(“yyyy”,”-10″,now()))#” to=”#year(dateAdd(“yyyy”,”10″,now()))#” step=”1″>
<option value=”#j#” <cfif j eq year(now())>selected</cfif>>#j#</option>
</cfloop>
</select>

i want to include checking funtion to validate to date must be greater or equal from date,
Do anyone got javascript for that or any code to check in that page while selection. what I mean before submit to another page for checking.

Thanks in advance

Shaffiq

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 04.2005 — You could use a function like this for that purpose:
<i>
</i>function checkDates(frm) {
with (frm.elements) {
var fromDate = new Date(from_year.value, from_month.value - 1, from_day.value);
var thruDate = new Date(thru_year.value, thru_month.value - 1, thru_day.value);
}
alert(fromDate + " &lt;= " + thruDate);
if (thruDate &lt;= fromDate) {
alert("From Date must be less than Thru Date.");
return false;
}
return true;
}

You would call it like this:
<i>
</i>&lt;form ...etc... onsubmit="return checkDates(this)"&gt;
Copy linkTweet thisAlerts:
@capik79authorJun 06.2005 — Hi phpnovice,

thx for the solution, its really help me.

thx again

regards

shaffiq
Copy linkTweet thisAlerts:
@phpnoviceJun 06.2005 — Cheers.
×

Success!

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