Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

text field data validation

 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • 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?
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic