...

View Full Version : General form validation script



bets
05-04-2004, 02:55 AM
I've been looking around for script that is flexible enough for various diffrent form and field names. The only thing i really want to check is if there is a value typed in or not. The thing is that i want it to error out an alert box with the form field value name that is blank. Ex: "Please fill out the NAME field".

This error would be typical for all other fields "Please fill out the ZIPCODE" field". Does any one have a flexible enough script for this or any ideas?

dswimboy
05-04-2004, 03:12 AM
how does this work for you? it checks to make sure the email address has a @ and a . in it, too

<SCRIPT><!--
function validate() {
if ((document.feedback.email.value=="")||
(document.feedback.body.value=="")||
(document.feedback.subject.options.value=="choose"))
{
alert ("You must fill in all required fields!")
return false
}
}
function emailcheck() {
var e=document.feedback.email.value
if ((e.indexOf("@")==-1)||
(e.indexOf(".")==-1))
{
alert("Please input a valid email address!")
document.feedback.email.focus()
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<H1>Feed Back Form</H1>
<P>
<FORM enctype="text/plain" name="feedback" method="post" action="mail_form.cgi" onsubmit="return validate()">
<P>Subject
<SELECT name="subject">
<OPTION value="choose" selected>--Choose A Subject--</OPTION>
<OPTION value="question">Ask A Question</OPTION>
<OPTION value="comment">Give A Comment</OPTION>
<OPTION value="change">Suggest A Change</OPTION>
<OPTION value="other">Other</OPTION>
</SELECT>
<P>E-mail:
<INPUT size="26" name="email" onblur="emailcheck()">
<P>Feedback:
<P>
<TEXTAREA name="body" rows="4" cols="55"></TEXTAREA>
<P>
<INPUT type="submit" value="Send">
<INPUT type="button" value="Reset">
</FORM>

glenngv
05-04-2004, 03:32 AM
Check out beetle's fValidate (http://www.peterbailey.net/fValidate/). It is a comprehensive form validation tool that covers all types of fields.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum