Reputation: 1765
I'm passing list from java action class to jsp file through the session variable and i need set that list to the hidden input field and get that list to the jquery function I used following method to do that
I use this code bock for set list to the input field
<c:if test="${not empty sessionScope.myList}">
<c:forEach items="${sessionScope.myList}" var="item" varStatus="itemLoop">
<input class="myClass" type='hidden' value='${item}'/>
</c:forEach>
</c:if>
jquery method
$(document).ready(function () {
$('input.myClass').each(function() {
// do some work
});
}
But problem is its working first time only, my list values are changed by ajax call, but after changing list size and value it's not set the value accordingly. Fist time created input fields are also there when I set the value second time. I think my method is not the correct way to do this, if any one know the better way to do this please help me Thank you..!
Upvotes: 0
Views: 469
Reputation: 10782
But problem is its working first time only, my list values are changed by ajax call, but after changing list size and value it's not set the value accordingly fist time created input fields are also there
You need to remove the created elements first:
$("input.myClass").remove();
Or if you know the container of your elements you can do:
var $parent_container = $("your-selector-for-the-container");
$parent_container.empty();
I think my method is not the correct way to do this if any one know the better way to do this please help me
I'm normally not a fan of global variables, but in your case a global variable might be better than keeping this info (your list items) in the DOM.
Upvotes: 1