I am new to jQuery and stuck with this problem for quite a while now.
I am using jQuery ui datepicker in input fields which are dynamically added on click of a button. The date picker works only for the first instance of input box. Have tried searching for a solution, but no luck. Any help will be greatly appreciated. Thanks
jQuery code
$( ".datepicker" ).datepicker({
inline: true,
dateFormat: "yy-mm-dd"
});
Html Code
<div id="newlink">
<div>
<table style="border: 1px solid black;">
<tr>
<th>Date:</td>
<td>
<input type="text" name="linkurl[]" id="Editbox18" class="datepicker" style="width: 147px; height: 23px; z-index: 2; color: black" autocomplete="off">
</td>
</tr>
<tr>
<th>Remark:</td>
</tr>
<tr>
<td>
<textarea name="linkdesc[]" size="1" id="Editbox19" style="width: 550px; height: 45px; z-index: 2; color: black" autocomplete="off"></textarea>
</td>
</tr>
</table>
<br>
</div>
</div>
<br>
<p id="addnew">
<input onclick="new_link()" type="button" name="linkdesc[]" value="Add More" style="width: 80px; height: 24px; z-index: 136; color: black;">
</p>
<!-- Template -->
<div id="newlinktpl" style="display: none"> <font size="1.5">
<hr style="width: 75%; margin-left: -5px;" /> <br />
<div>
<table style="border: 1px solid black;">
<th>Date:
</td>
<td><input type="text" name="linkurl[]" id="Editbox"
class="datepicker"
style="width: 147px; height: 23px; z-index: 2; color: black"
autocomplete="off"></td>
</tr>
<tr>
<th>Remark:
</td>
</tr>
<tr>
<td><textarea name="linkdesc[]" size="1" id="Editbox19"
style="width: 550px; height: 45px; z-index: 2; color: black"
autocomplete="off"></textarea></td>
</tr>
<script type="text/javascript">
var ct = 1;
function new_link() {
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = ' <input onclick="delIt(' + ct
+ ')" type="button" value="Del" style="position:relative; top:-20px; left:600px; color:black; width:50px;height:20px;z-index:136;">';
div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
// function to delete the newly added set of elements
function delIt(eleId) {
d = document;
var ele = d.getElementById(eleId);
var parentEle = d.getElementById('newlink');
parentEle.removeChild(ele);
}
</script>
</td>
</tr>
</table>
</div>
</font>
</div>