/    Sign up×
Community /Pin to ProfileBookmark

onSubmit two return functions

I have created a form which has two validation rules for the e-mail field, one to check the format and the other to check that the two e-mail addresses entered are the same.
I’ve been Googling around and, from what I’ve seen, the onSubmit cannot have more than two return functions (unless someone can correct me on this?). Therefore, I have been trying to put the two validation rules into one function but, because I’m such a newbie at JavaScripting, I can’t get them to work. I have tested both rules seperately and they work fine, I just can’t seem to put them together.

Or are there other, better ways to do this?

Here are the two functions:

[U]Function 1[/U]
function verify_email(email, email_conf)
{
if (email.value == ” || email_conf.value == ”)
{
alert(‘Please fill out both e-mail fields.’);
return false;
}
else if (email.value != email_conf.value)
{
alert(‘The e-mail addresses entered do not match.’);
return false;
}
else
{
md5hash(email, document.email_us.form1.email);
md5hash(email_conf, document.email_us.form1.email_conf);
return true;
}
return false;
}

[U]Function 2[/U]
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf(“@”)
ipos=value.indexOf(“.”)
dotpos=value.lastIndexOf(“.”)
if (apos<1||ipos<1||dotpos-apos<2)
{alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,”Please include a valid e-mail address”)==false)
{email.focus();return false}
}
}

Any help would be much appreciated.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Apr 04.2006 — you can try calling both functions instead of combining them:

onsubmit="return (function1() && function2())"

Not what you asked, but easier for you to start out with.

Eric
Copy linkTweet thisAlerts:
@tina180authorApr 04.2006 — Ah, you're a genuis!! It works now, thank you!!
Copy linkTweet thisAlerts:
@silverstar2569Apr 04.2006 — i have this problem as well but even after i try using the solution above, it still doesnt work
Copy linkTweet thisAlerts:
@A1ien51Apr 04.2006 — i have this problem as well but even after i try using the solution above, it still doesnt work[/QUOTE]


Are both your functions returning true or false?

Eric
Copy linkTweet thisAlerts:
@silverstar2569Apr 04.2006 — they both return true
Copy linkTweet thisAlerts:
@A1ien51Apr 04.2006 — Are you positive they are returning true? Test it by adding an alert statemenet in your functions to make sure. Sometimes it does strange things.

You might also want to show code.

Eric
Copy linkTweet thisAlerts:
@silverstar2569Apr 04.2006 — it does work, sorry, i misspelt one of the functions
×

Success!

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