Thanks for taking the time to read this.
I have an unknown number of (dynamically inserted) input elements in a form, to each of which I want to attach the datepicker widget included in jQuery UI.
All of the input elements that I want to attach the datepicker to have a class of "date-pick". Obviously because we have more than one matching element we need more than just a class name so that the date value gets returned to the originating field rather than just the first match.
Ordinarily I'd probably just do something like:
$("input.date-pick").each(function(){
$(this).datepicker({dateFormat: "yy-mm-dd"});
});
However in the code I'm working with, the input elements do not have unique IDs until the form data is saved (something that I'm unable to change), though they do have unique name attribute values of the format name ="field_id_x[y][z]".
which, when the form is saved then gets converted to an id of the format id="field_id_xyz"
.
So my question is, can anyone show me how to loop through all the input elements with a class of "date-pick" based on their name attribute values?
Thanks again for your time and attention.
(PS It might also be worth mentioning that the number of matching input elements in the form can be increased/decreased by the user on the fly.)