Results 1 to 2 of 2
  1. #1
    zeljkosh is offline Member
    Join Date
    Jan 2017
    Rep Power

    Default Calling JS function inside jsp for:Each loop

    I have a jsp page that shows some info about users, it basicly lists bunch of accounts, and it has two options to edit account or to delete it : the code goes something like this :

    Java Code:
    <c:forEach var="createAccount" items="${page.content }">
    		<c:url var="editLink" value="/editaccount?user=${createAccount.user }"/>
    		<c:url var="deleteLink" value="/deleteaccount?user=${createAccount.user }"/>
    			<div class="panel panel-default">
    				<div class="panel-heading">
    					<div class="panel-title">
    						Account name:
    						<div>${createAccount.user_name }</div>
    				<div class="panel-body">
    					<div>${createAccount.user_email }</div>
    					<div class="edit-links pull-right">
    						<a href="${editLink }">edit</a>|<a   href="${deleteLink}" onclick="return confirm ('Are you absolutly sure!?');">delete</a>
    And this code work flawlessly, i have no issues with it, how ever i wanted to change default confirm dialog, with bootbox.js confirm dialog, and i stumbled upon a problem:
    What i did is next, i deleted onclick event from my link, and replaced it with id="alert" and then added this script at the end of my page, before closing body tag.

    Java Code:
        $(document).on("click", ".alert", function(e) {
                message: "Are you sure you want to delete this Account?",
                buttons: {
                    confirm: {
                        label: 'Yes',
                        className: 'btn-success'
                    cancel: {
                        label: 'No',
                        className: 'btn-danger'
                callback: function (result) {
                            var x= href="${deleteLink }"
                              window.location = href;
    and this does somewhat work, i get a prompt, and i can confirm or cancel, however it always deletes the LAST index in my loop, if i click on first or third account it does not matter, it will always delete last one,
    so i do know that problem is that my on click event from javascript does not get good user parameter, but i just dont know how to solve this. Any help is welcomed, thank you !

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Calling JS function inside jsp for:Each loop

    Look in the code generated and see what value it has put into your href in the Javascript.

    Since this is after the loop, what value do you expect to be in that code?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Lifecycle of objects created inside a function?
    By petzeee in forum New To Java
    Replies: 2
    Last Post: 01-25-2013, 09:22 AM
  2. Calling a Function
    By skmightymouse in forum New To Java
    Replies: 16
    Last Post: 04-24-2012, 10:39 PM
  3. Calling native function
    By Bharathgl in forum Advanced Java
    Replies: 2
    Last Post: 01-25-2012, 10:43 PM
  4. Calling function in Javascript- from other function
    By jdigger in forum New To Java
    Replies: 1
    Last Post: 02-27-2011, 09:00 PM
  5. Calling the Function again
    By Swetz55 in forum New To Java
    Replies: 2
    Last Post: 12-19-2009, 11:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts