/    Sign up×
Community /Pin to ProfileBookmark

confirm problem

Hi all –

I am having a problem with the onsubmit event handler. Onsubmit, I call the function below. The problems I am having are:
1) If the confirm dialog is used, the redirect does not occur – the form processes as normal.
2) If the alert dialog is used, even though the function returns false after the dialog, the form still submits! I have been wrestling with this for a while now.
Thanks for your help.

[code]
function enterInfo() {
if (validate() == 1) {
if (confirm(“Would you like to enter our monthly prize drawing? (OK = Yes, Cancel = No)”)) {
window.location = “enter_info.php”;
return true;
}
else {
window.location = “thank_you.php”;
return true;
}
}

else if (validate() == -1) {
alert(‘Please respond to all questions.’);
return false;
}
}
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERAug 07.2007 — Couple of questions:

1. Does your <form ...> tag include onSubmit="return enterInfo()"?

2. Does your 'validate()' function return true (for success) or false (for failure)? Can not tell, but looks like it returns -1 or 1.

3. What does 'enterInfo()' return if validate() is not either 1 or -1?

May want to add some strategic 'alert()'s to see if what you expect to happen ... is. :eek:
×

Success!

Help @thefortrees 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.26,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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