I receive list of feeds.Each feed has unique number feed.id.
<c:forEach items="${feedList}" var="feed">
<td><input readonly="readonly" id="feedId"
value="<c:out value="${feed.id}" />" /></td>
<td><c:out value="${feed.name}" /></td>
<td><a
href="FeedController?action=delete&id=<c:out value="${feed.id}"/>">Delete</a></td>
<td><a
href="FeedItemController?action=feedItemListAsc&id=<c:out value="${feed.id}"/>">View</a>
</td>
<td><a href="#dialog" name="modal">Edit</a></td>
</c:forEach>
Pressing edit opens modal window with input name:
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({
'width' : maskWidth,
'height' : maskHeight
});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
//transition effect
$(id).fadeIn(2000);
});
<div id="boxes">
<div id="dialog" class="window">
<table class="userInput" border="1">
<tr>
<td colspan="2"><input type="text" id="feedName" />
</td>
</tr>
<tr>
<td><input type="submit" id="renameFeed" value="Submit"></td>
<td>
<a href="#" class="close">Close it</a>
</td>
</tr>
</table>
</div>
<div id="mask"></div>
</div>
and finally getting name from modal window and id parameter from forEach block with ajax:
$('#renameFeed').click(function() {
var name = $('#feedName').val();
var id = $('#feedId').val();
var action = 'edit';
var data = "feedName=" + name + "&id=" + id + "&action=" + action;
$.ajax({
type : "Get",
url : "FeedController",
data : data,
success : function(result) {
if (typeof (result) != 'undefined') {
}
},
error : function(error) {
console.log("error" + error);
}
});
});
After that i want to change name in database using servlets and in my html page.
I need to get feed.id from for each when edit button was pressed and then when <input type="submit" id="renameFeed" value="Submit">
was pressed send the value to servlets.
Can easily get feed.name but have problem with passing feed.id
Maybe someone knows better solution with renaming using modal window and jQuery ajax?