Results 1 to 5 of 5

Thread: Form Validation??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263

    Form Validation??

    Ok. How do I submit a form to a script that will validate it and if there are any errors, take them back and display a msgbox telling them that there are, and then submit the form to the script that adds it to the database?
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Make your submit buttons normal buttons and in their 'onClick' event handler, call the validation function. Put the Form.submit() at the end of the function and if one of the validations fail, alert the user and 'return' so it never gets to the submit. You could even set the focus to the offending field for them to fix.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3
    New Member
    Join Date
    Jan 2005
    Posts
    13

    Re: Form Validation??

    Quote Originally Posted by monte96
    Make your submit buttons normal buttons and in their 'onClick' event handler, call the validation function. Put the Form.submit() at the end of the function and if one of the validations fail, alert the user and 'return' so it never gets to the submit. You could even set the focus to the offending field for them to fix.
    I followed your instructions but I get error: Object doesn't support this property or method: 'frmTPOnline.submit'

    HTML Code:
    <!-- Data Validation-->
    <SCRIPT LANGUAGE = "VBScript">
    Sub Submit_OnClick()
    	if frmTPOnline.txtquantity.value = "" then 
    		MsgBox "empty!"
    		exit Sub
    	else
    		msgbox "OK!"
    	end if
    
    frmTPOnline.submit()
    
    End Sub
    </SCRIPT>

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Form Validation??

    Its better to use JavaScript as VBScript is only supported in IE. Here is the standard way of validating a form.
    HTML Code:
     <html>
    	<head>
    		<script>
    			function validate()
    			{
    				if (document.form1.txtName.value=="")
    				{
    					alert("Please enter your name");
    					document.form1.txtName.focus();
    					return false;
    				}
    
    
    				if (document.form1.txtEmail.value=="")
    				{
    					alert("Please enter your email");
    					document.form1.txtEmail.focus();
    					return false;
    				}
    
    			}
    		</script>
    	</head>
    	
    	<body>
    		<form name=form1 onsubmit="return validate()">
    			Name : <input type=text name=txtName><br>
    			Email: <input type=text name=txtEmail>
    			<input type=submit>
    		</form>
    	</body>
    </html>
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5
    New Member
    Join Date
    Jan 2005
    Posts
    13

    Re: Form Validation??

    Thank you for the code but in the intranet we use mostly VBscript.
    I found the cause of the problem in my code: The form.submit couldnt be invoked because there was another object (button) with the name "submit" so there was conflict. I renamed the button to "cmdSubmit" and everything went fine since then.

Posting Permissions

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



Click Here to Expand Forum to Full Width