1

I have created a div having dyanamically created textboxes.these dynamic textboxes are also given ID dynamically as the number of textboxes are going to be dependent on the number of values present in database.

I added 'text_' infront of every textbox id creating dynamically.

Now the problem starts.i want to add javascript validation to all those dynamic textboxes.as javascript requires an ID,Name, or Class..but as they are dynamic wat shud i use? is there any textbox array having all textbox id's??plz help.or any other way to apply js to those dynamic textboxes.

Hope u will understand my problem from above story...

1
  • If you want to add validation, then the most important thing to know for each text input is what valid values it can contain. If they're all the same, then it doesn't matter; you can apply the same validation code to all of them. If they're different, then you must know that while they're being created, so just give them an appropriate "class" value. Commented Feb 2, 2011 at 13:46

2 Answers 2

1

just get all textboxes to array using getElementsByTagName function, then test if their ids start with your prefix ;-)

Sign up to request clarification or add additional context in comments.

Comments

0

using jquery you can use the :nth-child() selector to select any element you want to validate.

Example:

$('form input:nth-child(2)').validate();

This will validate the second input for your form. Of course you have to adapt it in the validation method you use.

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.