Click here to Skip to main content
13,141,576 members (35,224 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a for loop writing out a list of records to a web page, now what I want is to display a link that displays a date, when clicking the link it brings up a dialog box for the user to edit the date, I got that rite but some how when a second record is added it doesnt seem to work,

Posted 23-Apr-13 20:55pm
Zoltán Zörgő 24-Apr-13 2:59am
How exactly do you apply with jquery the datepicker on the elements?
nathan666 24-Apr-13 3:01am
Below is the jquery initialized

$(function() {
$("#timeOff").datepicker({ dateFormat: "dd/mm/yy", yearRange: 'c:c+10', changeMonth: true, changeYear: true});
$(this).datepicker({ dateFormat: "dd/mm/yy", yearRange: 'c:c+10', changeMonth: true, changeYear: true});

and this is where the datepicker instance is created

<input id="timeOff2" class="datepicker"/></input>
nathan666 24-Apr-13 3:39am
so it would be

"<input type="text" name="timeOff" class="DatePicker-needed">|"

and as the loop runs it creats multiple instances of name="timeOff" with class="DatePicker-needed"?
Zoltán Zörgő 24-Apr-13 4:05am
More or less. Look here:
Names should be unique in a form, but you can use arrays: <input type="text" name="timeOff[]" class="DatePicker-needed">

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You wrote, your are using a loop, but you apply the feature based on ID ('#timeOff2'). But there can be only one element on the page with such ID. I am not wondering that it does not work, you mishandle the html standard. Don't reuse ID within page. In this case you should use class. And you don't need each either.
$('.DatePicker-needed').datepicker({ dateFormat: "dd/mm/yy", yearRange: 'c:c+10', changeMonth: true, changeYear: true});

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100