• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

text field data validation

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If I have a set of input text fields with the same name , for example:
<input type="text name="test" value="Type your name">
<input type="text name="test" value="Type your name">
The input fields are added dynamically, so the number of the input fields is not known in advance.
I want user to type something in the input fields before submission.
How can I do the input data validation?
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,
If all your INPUTs are of type "text" (i.e., no radio buttons, checkboxes, etc.), you could use GetElementsByTagName(...) to return a NodeList of all INPUT elements, then loop through them and perform validation on each one.
Other than that, I'd try to come up with a scheme by which you can dynamically generate a new name for each field. You could maintain a count of INPUT fields and increment it each time you add one to the form, concatenating the last count number to the field's name. It's kind of kludgey, but it means that you can later loop through your elements more easily while still treating them as seperate entities.
hth,
g.
reply
    Bookmark Topic Watch Topic
  • New Topic