|
-
Aug 11th, 2002, 12:15 PM
#1
Thread Starter
Stuck in the 80s
JavaScript: Form Validation
What's wrong with this code?:
Code:
<script>
function check(f) {
if (f.title.value == "") {
alert("You must have a subject.");
} elseif (f.body.value == "") {
alert("You must have a body in your post.");
} elseif (f.body.value.length > 10000) {
alert("Your message is too long. The max is 10000 characters.");
} else {
document.f.submit();
}
}
</script>
<form action="post.php" method="post">
...
<input type="button" value=" Submit " onClick="check(forms(0))">
It's just supposed to validate the form and make sure all the fields are filled.
Last edited by The Hobo; Aug 11th, 2002 at 12:36 PM.
-
Aug 11th, 2002, 01:10 PM
#2
Thread Starter
Stuck in the 80s
I got this working:
Code:
<script language="JavaScript" type="text/javascript">
function check() {
f = document.postform;
if (f.title.value == "") {
alert("You must have a subject.");
event.returnValue = false;
} else if (f.body.value == "") {
alert("You must have a body in your post.");
event.returnValue = false;
} else if (f.body.value.length > 10000) {
alert("Your message is too long. The max is 10000 characters.");
event.returnValue = false;
} else {
event.returnValue = true;
}
}
</script>
Can anyone tell me if it's cross browser compliant?
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
|