I'm new to jquery, I'm working on a web page which needs generating text boxes dynamically with autocomplete facility. I don't know how bind event with generated textbox. my code looks as follows:
$(document).ready(function () {
var counter = 1;
$(".addButton").live("click", function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.html('<TABLE><TR><TD>' + '<input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" ></TD> <TD><a href="#" value="addButton" class="addButton">Add</a> </TD></TR></TABLE>');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
});
});
and post query
function fillTextBox(text) {
$.ajax(
{
type: 'POST',
url: '@Url.Action("_AutoCompleteAjaxLoading", "CommandEntity")',
async: true,
data: { text: text},
dataType: "json",
traditional: true,
success: function(data) {
//what I should do here?
},
error: function(xhr, ajaxOptions, thrownError) {
}
});
}