aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes validate multiple form fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "validate multiple form fields" Watch "validate multiple form fields" New topic
Author

validate multiple form fields

rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
Hello
I have a form with multiple fields in it. I don't know how many I will have. The field names will be something like this
name1 number1 address1
name2 number2 address2
and so on the user is entering in a number of how many times they want to split a charge up so they get that many rows and I create the form/table using jsp.
what i need to do is make sure that there is data entered into each of the fields on sumbit
but i'm stuck can someone help me out?
Thanks!
O users all (are supposed to) use netscape
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Well, if I had to do it and I didn't know how many fields were going to be on my form, I would probably get a reference to the form and then loop through the form's elements, check for each to have a value. I wanted to include a code snippet, but my first effort was unsuccessful and my wife just came home and shut me down.
rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
Thanks
Actually that is what i'm doing but i can't figure out how to test if the user enters in only spaces as well. Can u include a code snippet now
This is what I have so far splitSize is a jsp var that = the amount of rows i will have * 5 for the number of fields per row
function validateMe(theForm)
{
var emptyFields=""
var size = <%=splitSize%>*5;
for (i=0; i <= size; i++)
{
if(theForm.elements[i].value=="")
{
comma=(emptyFields=="")?"":", "
emptyFields=emptyFields+comma+theForm.elements[i].name}}
{
if (emptyFields!="")
{
alert('All Fields must contain data. \n'+'Please return and complete the form.')
return false
}
}
}
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Well I was going to try to craft something, but I see that you got this pretty neat answer in your other post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validate multiple form fields