Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
Hi,
 

 
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,
 
Thanks
Posted 23-Apr-13 21:55pm
Comments
Zoltán Zörgő at 24-Apr-13 2:59am
   
How exactly do you apply with jquery the datepicker on the elements?
nathan666 at 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});
$('#timeOff2').each(function(){
$(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 at 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ő at 24-Apr-13 4:05am
   
More or less. Look here: http://www.johnrockefeller.net/html-input-forms-sending-in-an-array-in-php/
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
good
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});
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2014
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