Maybe this could help you.
If you have this html:
<input type="text" id="datepicker1" class="datepicker">
<input type="text" id="datepicker2" class="datepicker">
<input type="text" id="datepicker3" class="datepicker">
You could put multiple datepicker for each one like this:
$(".datepicker").datepicker();
The jQuery selector returns an array of elements, so you could check
how many fields like this:
$(".datepicker").length;
Or maybe check it by the id, using the each method:
$(".datepicker").each(function() {
if($(this).attr("id") == "datepicker1") {
$(this).datepicker();
}
});
References:
http://docs.jquery.com/Selectors/class#class
http://docs.jquery.com/Core/each
http://docs.jquery.com/Attributes/attr#name
On Jul 23, 1:31 pm, Mr Fett <[email protected]> wrote:
> Hi all,
>
> I've been trying to use the datePicker with multiple date fields but
> if ever I used a selector that should reference multiple instances
> (for example using a class ".datePicker"), only the first field works.
>
> Obviously I can get around this *IF* I know how many date fields there
> are and what their IDs are but I don't as they are dynamically driven.
>
> Has anyone had any success with this?
>
> Thanks
>
> Bob
>
> On Jul 15, 12:49 am, gil <[email protected]> wrote:
>
>
>
> > I don't know if I understand completely. But, here is a solution that
> > could work if you whant to set 2 or more input's with a datepicker
> > using only the id's.
>
> > html:
> > <input type="text" id="datepicker1">
> > <input type="text" id="datepicker2">
> > <input type="text" id="datepicker3">
>
> > javascript (option 1, one datepicker for each input):
> > $(function() {
> > $("#datepicker1").datepicker();
> > $("#datepicker2").datepicker();
> > $("#datepicker3").datepicker();
>
> > });
>
> > javascript (option 2, you can use the jquery selector to capture all
> > the desired inputs and will give you an array of objects and then the
> > function datepicker() will apply to each element on the array, similar
> > to the previous post):
> > $(function() {
> > $("#datepicker1,#datepicker2,#datepicker3").datepicker();
>
> > });
>
> > On Jul 13, 9:42 pm, JohnIke <[email protected]> wrote:
>
> > > I have been trying to work out this same problem. I am not a
> > > JavaScript wiz, but have been trying a number of ways to get things
> > > going. The problem I see with your above solution is that you can't
> > > set different options on each date field if you don't give them an
> > > id. Not really sure what the best solution is. We need to set up
> > > different default values and options on each different date field on
> > > the page.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---