Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
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});
$('#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 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: 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

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.
JavaScript
$('.DatePicker-needed').datepicker({ dateFormat: "dd/mm/yy", yearRange: 'c:c+10', changeMonth: true, changeYear: true});
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900