/    Sign up×
Community /Pin to ProfileBookmark

validation Alerts

Hey Im using this script to check/validate the fields in my form and I was wondering how to make it dispay all the errors at once. Say the person leaves all the fields empty, and alert box will pop-up only telling them to fill in the first field. And it just keeps going in order, one at a time, until all the fields are filled in/valid, how can I make it to display all the errors at one time?

[CODE]
<script type=”text/javascript”>
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==””)
{alert(alerttxt);return false}
else {return true}
}
}

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

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(fname,”Please enter your first name.”)==false)
{fname.focus();return false}
if (validate_required(email,”Please enter your e-mail address.”)==false)
{email.focus();return false}
if (validate_email(email,”Not a valid e-mail address!”)==false)
{email.focus();return false}
if (validate_required(message,”Please enter your message.”)==false)
{message.focus();return false}
}
}
</script>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinNov 12.2006 — ok, I'm too lazy to read your code right now (drunk) but.....the first thing I would say is that if you gave me 5 alerts one after another to tell me I had fooked up....I would not come back to your site unless you had something special!

what you need is a generic error handler that shows a message in red [b]above[/b] the item causing error, and as the errors are taken care of, the error handler is run again so that each resolved error is now not shown in red.

if this is what you are looking for, let m,e know...I have such an error handler that will do just that....gratis of course!

//erlin!
Copy linkTweet thisAlerts:
@novemberGreyauthorNov 12.2006 — could I tryout your error handler?
×

Success!

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