wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes text field data validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "text field data validation" Watch "text field data validation" New topic
Author

text field data validation

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
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?


Thanks,<br />Mike
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: text field data validation