/    Sign up×
Community /Pin to ProfileBookmark

form validation driving me bonkers!

Hi!

I’m trying to validate a simple guest book.
It must:

a) produce an alert when the email address is invalid;
b) produce an alert when a catagory of visitor is not selected;
c) produce an alert box informing them of the info that they have put in.

I can only get any 2 of the following working.. never all three!

Any ideas?

the script and html page are attached

Thanks

luds

[upl-file uuid=8c018e40-9260-431d-bfea-d416d184c3a3 size=2kB]formvalidation.txt[/upl-file]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Apr 29.2003 — Check this form out.It will help you understand the whole concept

http://68.145.35.86/skills/javascripts/UltimateFormValidator.html
Copy linkTweet thisAlerts:
@NedalsApr 29.2003 — There are a few errors in your javascript. Here is a working version. PLEASE look it over and understand what I did.

function submitIt(feedbackform) {

//if (document.feedbackform.catagory != 0) { ... deleted

//test 1

var catagorytype = "";

for (i = 0; i < document.feedbackform.catagory.length; i++) {

// removed ';' after ..checked);

if (document.feedbackform.catagory[i].checked) { catagorytype = document.feedbackform.catagory[i].value; }

}



if (!catagorytype) {
alert("Please enter a catagory!");
return false
}


//test 2 - removed extra '{ }'

if (re.test(feedbackform.emailaddress.value)) {

alert("Your Name: "+ feedbackform.yourname.value + "nYour email: "+ feedbackform.emailaddress.value + "nYour Catagory: "+ catagorytype + "nYour Comments: "+ feedbackform.comments.value)

return true

} else { // else was missing

alert("Invalid email address")

feedbackform.emailaddress.focus()

feedbackform.emailaddress.select()

return false

}

}
Copy linkTweet thisAlerts:
@ludsauthorApr 30.2003 — many many thanks, Khalidali63 and Nedals!

Not only do I have a script that works properly now... but I understand more javascript too!

Thank you for your time and patience!

luds ?
×

Success!

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