/    Sign up×
Community /Pin to ProfileBookmark

sub onclick validateform() goes to next webpage nomatter what.

When I find errors in my validateform() script I want to stay on the form and let the user fix the errors. My code is not working – it goes to the next webpage nomatter what? How do you get it to stay. I believe if the onclick validateform() is false it should stay. I must be doing something wrong.

Newbie – TIA


———–

function ValidateForm() {
var flag = true
var Tester = document.forms.guestbook
if (Tester.Gname.value == “”) {
alert(“Please enter a name.”)
flag = false
}
if (checkemail() == false) {
alert(“Please input a valid email address.”)
flag = false
}
if (Tester.security_code.value != Tester.code.value) {
alert(“Please enter a correct security code.”)
flag = false
}
alert(flag)
if (flag == true) {
document.forms.guestbook.submit()
}
}


—————————–

<input type=”submit” name=”submit” value=”Submit” onClick=”ValidateForm()”/>


——————————–

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangJul 06.2007 — function ValidateForm() {
var Tester = document.forms.guestbook
if (Tester.Gname.value == "") {
alert("Please enter a name.");
return false;
}
if (checkemail() == false) {
alert("Please input a valid email address.");
return false;
}
if (Tester.security_code.value != Tester.code.value) {
alert("Please enter a correct security code.");
return false;
}
document.forms.guestbook.submit();
}


-----------------------------

&lt;input type="submit" name="submit" value="Submit" onclick="return ValidateForm()"/&gt;
×

Success!

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