/    Sign up×
Community /Pin to ProfileBookmark

Keep process stopped when alert ‘OK’ pressed

This function checks dates for validitity, with return if all dates are correct:

[code]
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
return;
}
else {
if (from.value == “” || to.value == “”)
alert(“Both dates must be entered.”);
else
alert(“To date must occur after the from date.”);
}
}
[/code]

In the related form, the submit button is configured like so:

[code]
<input type=”Submit” name=”Submit” onClick=”doDateCheck(this.form.from, this.form.to);” value=”Send”>
[/code]

When I attempt to submit the form with invalid dates, this picks up the failures, but when the OK button of the alert box is clicked, the form then posts as if the values had been correct.

I want the precess to stop until the input dates have been corrected to an acceptable value, and the submit button is re-pressed. How to I go about that?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@kiwibritauthorJul 07.2007 — Thank you for coming back on this.

So, as I understand it, if the function is re-written like this:
<i>
</i>function doDateCheck(from, to) {
if (Date.parse(from.value) &lt;= Date.parse(to.value)) {
return true;
}
else {
if (from.value == "" || to.value == "")
alert("Both dates must be entered.");
return false;
else
alert("To date must occur after the from date.");
return false;
}
}


and the form is coded:

<i>
</i>&lt;form action="feedback.php" method="post" onSubmit="return doDateCheck(this.form.from, this.form.to)"&gt;
&lt;pre&gt;
From date &lt;input type=text name=from onBlur="checkdate(this)" size=11 maxlength=11&gt;
To date &lt;input type=text name=to onBlur="checkdate(this)" size=11 maxlength=11&gt;

&lt;input type="Submit" name="Submit" value="Send"&gt;
&lt;/pre&gt;
&lt;/form&gt;



All should now be well. Unfortunately, entering a false date is now ignored - so clearly I am missing a trick. I'd be grateful for a further steer on this.
×

Success!

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