There are many universal form validation functions out there. But I created this very quick function to very easily check for input, without modifying your form fields in any way, and without have to check each field individually. The script just checks for a value, it doesn't validate the format (like an email address), because that's very easy to add, so you can do it yourself!
All you do is put the name of each field in the array, and it quickly loops through the array, checks the field, and fails if one of the fields is empty
function checkForm() {
f = document.form1;
var isGood = true;
var required = new Array();
required[0] = "email";
required[1] = "password";
required[2] = "first_name";
required[2] = "last_name";
required[3] = "country";
for(i in required) {
if(f.elements[i].value=="") {
isGood = false;
break;
}
}
if(!isGood)
alert("Please fill in all of the required fields.");
return isGood;
}
//-->
</script>
Then put this in your form code:
<form name="form1" method="post" action="" onSubmit="return checkForm();">
11 Comments
how do i work this thing???
i also forgot to ask you if this would work on a game sight
It would work on any site. As explained above, just include the code and reference it in your form. It's that simple!
i'm sorry but can you explain how to set up a form for a game that already exists, like runescape, thx
If you don't know how to create an HTML form, you may need to search online for a basic HTML tutorial, sorry
I see the script ending tag, i was wondering where does the script start.
where is your beginning tag
i'm sorry but can you explain how to set up a form for a game that already exists
Hi dude, this is the only thing I found on the net that works for Fireworks. Thanks.
I have a few questions though.
How would I add to your code above the following:
Field was Number: and you can only enter seven numbers, with no characters (a-z).
And the last thing is the email, I'm not sure how I would fit it into the arry.
Firefox, not Fireworks. >.< Sorry!
I can only get it to validate the first two fields. Any idea why?
I did delete the last field "required[3] = "country";" because I didn't have that many fields.