0

I am doing an application in which end user can create 'n' number of textbox on runtime. If any user will demand 'n' number of textboxex then i have used control array e.g.

Enter the data: <input type="text" name="txtData[]" id="txtData1" /><br/>
Enter the data: <input type="text" name="txtData[]" id="txtData2" /><br/>

In whole application name based validation is used (http://www.javascript-coder.com/html-form/javascript-form-validation.phtml). I am unable to validate above functionality using this validation. Is any way to validate control array?

5
  • 4
    You don't have valid markup, you have an id attribute twice per element, and an ID needs to be unique in the entire page. Commented Dec 2, 2010 at 10:10
  • Is "txtData[]" a valid name for a form element? Doesn't look right. Commented Dec 2, 2010 at 10:38
  • All code is written with 'txtData[]' and execute properly. Only validation is remained. Commented Dec 2, 2010 at 10:47
  • Arrayish names are prefectly valid and required if you send the data to a PHP script which should create an array. Commented Dec 2, 2010 at 11:20
  • I'd suggest you to use a modern validation framework, e.g. the jQuery validation plugin. Just from the fact that the one you linked uses language="JavaScript" instead of type="text/javascript" it's probably old or not very good. Commented Dec 2, 2010 at 11:22

1 Answer 1

1

Just a thought, does it validate when you add the correct index to you names?

Enter the data: <input type="text" name="txtData[1]" id="txtData1" /><br/>
Enter the data: <input type="text" name="txtData[2]" id="txtData2" /><br/>

And you should maybe start the numbering from 0 if want to loop more easily trough your form data after submit. So:

Enter the data: <input type="text" name="txtData[0]" id="txtData0" /><br/>
Enter the data: <input type="text" name="txtData[1]" id="txtData1" /><br/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.