I need help with datepicker on dynamic created input fields...
I have this form:
<table id="reminder">
<tr>
<th>Payment Reminders</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td><label>Reminder</label></td>
<td><input type="text" name="payreminder[]" id="payreminder" class="input1" size="20" ><script>$('#payreminder').datepicker({dateFormat: $.datepicker.W3C, changeMonth: true, changeYear: true, yearRange: '2011:2020'}); </script></td>
<td><label>Description</label></td>
<td><input type="text" class="input1" name="paydescription[]" id="paydescription"></td>
<td> <a href="#" onClick="addReminder('dynamicInputReminder');" title="Add another">Add another</a></td>
</tr>
<tr>
<td colspan="6"><div id="dynamicInputReminder"></div> </td>
</tr>
</table>
And the javascript for adding more reminders is:
<script type="text/javascript" >
var counterReminder = 1;
var limit = 20;
function addReminder(divName){
if (counterReminder == limit) {
alert("You have reached the limit of adding " + counterReminder+ " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<td><label>Reminder</label></td><td><input type=\"text\" id=\"payreminder["+counterReminder+"]\" name=\"payreminder["+counterReminder+"]\" class=\"input1\" ></td><td><label>Description</label></td><td><input type=\"text\" id=\"paydescription["+counterReminder+"]\" name=\"paydescription["+counterReminder+"]\" class=\"input1\"></td>";
document.getElementById(divName).appendChild(newdiv);
counterReminder++;
}
}
</script>
The question is: How and where can I call the script bellow for the date picker so that it works for the dynamically created fields ?
<script>$('#payreminder').datepicker({dateFormat: $.datepicker.W3C, changeMonth: true, changeYear: true, yearRange: '2011:2020'}); </script>
Thanks a lot!