• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

validate multiple form fields

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic