user3391137 user3391137 - 4 months ago 10
Javascript Question

How to load the datapicker of the following context inside <td> </td>?

enter image description here

In he above code, I would like to add datepicker of input field which contains id as datepicker.

For this purpose i used the following js code in document.ready() func

$("tbody#docTab").click(function() {
var row = $(this).closest('tr');
row.find('#datepicker').removeClass('hasDatepicker').datepicker();
});


But i does not appear the datepicker while onclick the input field, What i have missed on this code?
Advanced thanks.

Answer

assign unique id to each element in html, here ids are being duplicated - instead of assigning same id to multiple inputbox - I would suggest add class "datepicker" to every input to whom you want to add datepicker:

<td>
   <input  type="text" name="sdate[]" class="datepicker" value="0000-00-00" />
</td>
<td>
   <input  type="text" name="edate[]" class="datepicker" value="0000-00-00" />
</td>

and in jquery:

$("tbody#docTab").click(function({
  $('.datepicker').removeClass('hasDatepicker').datepicker();  // you can directly add datepicker using its class name      
});
Comments