|
-
Nov 9th, 2008, 04:49 PM
#1
Thread Starter
Hyperactive Member
Form Validation
Are there any free frameworks or apis or pre-built javascript files that I can easily plug in for form validation?
-
Nov 10th, 2008, 04:18 AM
#2
Re: Form Validation
There is one here:
http://www.javascript-coder.com/html...lidation.phtml
Which is easy to use. The problem is this is not W3C compliant, so your page won't validate. I am currently working on something similar which is W3C compliant.
-
Nov 12th, 2008, 04:13 AM
#3
Re: Form Validation
You could just write your own, it won't be as heavy as a 'prepared' one.
-
Nov 12th, 2008, 05:25 AM
#4
Re: Form Validation
I am almost finished with an object oriented javascript form validation, similar to the one above.
The size of the script include is less than the average jpeg image.
If you just want a quick script to check required fields then something like this will do:
Code:
function validate()
{
var output = true;
var msg = "Please correct the following errors:\n";
if(document.forms["contact_us"].name.value.length < 3) { output = false; msg += "\n - Name is missing or too short."; }
if(document.forms["contact_us"].email.value.length < 5) { output = false; msg += "\n - Email address is missing or too short."; }
if(!output)
{
alert(msg);
return false;
}
else
{
return true;
}
}
And the HTML form:
Code:
<form action='somewhere.html' name='contact_us' method='post' onsubmit='return validate()'>
Name: <input type='text' name='name' />
Email: <input type='text' name='email' />
<input type='submit' name='form_submit' />
</form>
Note the onsubmit event in the <form> tag. This tells the form to call the validate function when submitted, the validate function returns true/false. If false the form will not be submitted, and a message will popup with the errors.
-
Nov 14th, 2008, 09:36 PM
#5
Re: Form Validation
Just added this to the Codebank: Easy form validation - http://www.vbforums.com/showthread.php?p=3380227
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
|