Solved

jQuery DatePicker on a table with multiple rows

Posted on 2010-11-19
2
671 Views
Last Modified: 2012-05-10
Hi,

I have a table as follows:

<ul class="xyz">
   <li>Date</li>
   <li>Start</li>
   <li>End</li>
</ul>
<ul class="abc">
   <li><input type="text" name="date0" id="date"></li>
   <li><...></li>
   <li><...></li>
</ul>
<ul class="abc">
   <li><input type="text" name="date1" id="date"></li>
   <li><...></li>
   <li><...></li>
</ul>
.
.
.
<ul class="abc">
   <li><input type="text" name="date100" id="date"></li>
   <li><...></li>
   <li><...></li>
</ul>

The last row can be any number as it depends on the number of queries being pulled out of the database.

Currently my datepicker scripts says

$(function() {       
        $( "#date" ).datepicker({
              minDate: 0,
              changeMonth: true,
              changeYear: true,
              dateFormat: 'dd-mm-yy',
              showOn: "button",
              buttonImage: "/images/calendar.gif",
              buttonImageOnly: true,
               showOtherMonths: true,
              selectOtherMonths: true              
        });      
});       

How do I change it so that it is executed whenever the user tries to select a date in any 'dateX' field?

Thanks

0
Comment
Question by:jagku
2 Comments
 
LVL 2

Accepted Solution

by:
marceloOrigoni earned 500 total points
ID: 34174271
the best way, is to add a class="date" to each field, like this:

<ul class="abc">
   <li><input type="text" name="date100" id="date" class="date"></li>
   <li><...></li>
   <li><...></li>
</ul>

and then execute the datepicker like this:

$(function() {      
        $( ".date" ).datepicker({
              minDate: 0,
              changeMonth: true,
              changeYear: true,
              dateFormat: 'dd-mm-yy',
              showOn: "button",
              buttonImage: "/images/calendar.gif",
              buttonImageOnly: true,
               showOtherMonths: true,
              selectOtherMonths: true              
        });      
});  

Marcelo
0
 

Author Closing Comment

by:jagku
ID: 34174332
Excellent - many thanks!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question