This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate multiple form fields

 
rich werth
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I was going to try to craft something, but I see that you got this pretty neat answer in your other post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic