I have the following code :
<td>
<div id="div<%# Eval("Id") %>" class="Display"><%# Eval("Display") %></div>
<div class="Actions">
</div>
<div class="Comment">
<span>Comment </span>
<input id="txt<%# Eval("Id") %>" type="text" width="400px" />
</div>
</td>
What I am looking for is, when i pressed EnterKey from
<input id="txt<%# Eval("Id") %>" type="text" width="400px" />
I want to append text in
<div id="div<%# Eval("Id") %>" class="Display"><%# Eval("Display") %></div>
how can I do this?
I did follow this (but not sure if this is the best way)
if (e.which == 13) {
var comment = $("#" + this.id).val();
var textId = "#" + this.id.replace("txt", "div");
$(textId).append(comment);
$.ajax({
type: "POST",
url: "Home.aspx/AddComments",
data: "{'id': '" + this.id.replace("txt", "") + "','comments': '" + comment + "'}",
dataType: "json",
contentType: "application/json",
success: function (response) {
alert(response.d);
}
});
}
Note : this is itemtemplate, so every div and input element have different id
A little modification of input tag
And then the required jQuery code
Hope it helps.