Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    General form validation script

    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?

  • #2
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how does this work for you? it checks to make sure the email address has a @ and a . in it, too
    Code:
    <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>
    "There is more than one way to do it."

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Check out beetle's fValidate. It is a comprehensive form validation tool that covers all types of fields.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •