Aakash Sahai
Aakash Sahai

Reputation: 4004

javascript and dynamic textboxes access

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...

Upvotes: 1

Views: 1028

Answers (2)

Sotiris
Sotiris

Reputation: 40066

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.

Upvotes: 0

Patrik Fiala
Patrik Fiala

Reputation: 56

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

Upvotes: 1

Related Questions