views:

19

answers:

1

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!

A: 

i would suggest the following:

<div id="title<%=ind%>"><%= list.get(ind).getTitle() %></div>

then

<input type="submit" name="submit" onclick="deleteNewsFunction(<%=ind%>);" id="submit_btn"/>

finally:

<script>
  function deleteNewsFunction(ind){
       var item = $('#title' + ind).val();
       alert(item);
  }
</script>
Andrey
It worked!! Thank you very very much!!!
novellino
@novellino don't forget to accept answer ;)
Andrey