How can I use a value of JSP in Javascript code?
Posted
by novellino
on Stack Overflow
See other posts from Stack Overflow
or by novellino
Published on 2010-06-03T08:59:49Z
Indexed on
2010/06/03
9:04 UTC
Read the original article
Hit count: 185
Hello, I have a list of elements, each of them appeared in my page through jsp. So I have this:
<div id="title"><%= list.get(ind).getTitle() %></div>
When I display the elements, as this tag is in for loop, I get everything right. Now I what to place a button for deleting each of this elements. What I have done is:
<input type="submit" name="submit" onclick="deleteNewsFunction();" id="submit_btn"/>
In the deleteNewsFunction() I just want to print the data.
<script>
function deleteNewsFunction(){
var item = $('#title').val();
alert(item);
}
</script>
The problem is that the title var gets always the first item even if I am clicking on the button of the second item. I was thinking that maybe a solution is to add the "list.get(ind).getTitle()" as a parameter in the function like deleteNewsFunction(<%=list.get(ind).getTitle()%>) but then it did not work at all.
Does anyone know how to help me?
Thanks a lot!
© Stack Overflow or respective owner