|
-
Aug 2nd, 2001, 01:35 PM
#1
Thread Starter
Hyperactive Member
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
-
Aug 2nd, 2001, 01:52 PM
#2
Frenzied Member
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..
-
Jan 25th, 2005, 02:43 AM
#3
New Member
Re: Form Validation??
 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>
-
Jan 25th, 2005, 06:43 AM
#4
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 : 
-
Jan 26th, 2005, 02:34 AM
#5
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|