Solved

jQuery DatePicker on a table with multiple rows

Posted on 2010-11-19
2
667 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
Comment Utility
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
Comment Utility
Excellent - many thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now