1

can anyone tell me what's wrong in this line?

Template:

<c:forEach items="${templateList}" var ="temp">
   <td>
      <button onclick = "edit(${temp.id});" data-target="#myModal1" data-toggle="modal" title="Edit" class="btn btn-success btn-sm"><i class="fa fa-edit"></i>Edit</button>
   </td>
   <td>
      <button data-target="#myModal2" title="Attach Link" data-toggle="modal" class="btn btn-success btn-sm"><i class="fa fa-paperclip"></i></button>
   </td>
   <td>
      <button data-target="" data-toggle="modal" title="duplicate" class="btn btn-success btn-sm"><i class="fa fa-copy"></i></button>
   </td>
</c:forEach>

and as well as this function

<script>
   function edit(id){
      $.get("get/" + id,function(result){
         $("#myModal1").html(result);
         alert("dnrbufevc ");
      });
   }
</script>
7
  • Why cant you use ng-click and use your function inside your controller? Commented Jun 6, 2018 at 1:24
  • @Senal actually taglib I am using so I am just selecting single value from the list of value that's why I want mandatorialy go with $ selector Commented Jun 6, 2018 at 1:29
  • Does ${temp.id} render as an actual string when you inspect the button? Otherwise you're just sending a string to the JS not the ID you're intending Commented Jun 6, 2018 at 1:30
  • Can you update your answer with the whole html Commented Jun 6, 2018 at 1:34
  • @Doug <c:forEach items="${templateList}" var ="temp"> <td><button onclick = "edit(${temp.id});" data-target="#myModal1" data-toggle="modal" title="Edit" class="btn btn-success btn-sm"><i class="fa fa-edit"></i>Edit</button></td> <td><button data-target="#myModal2" title="Attach Link" data-toggle="modal" class="btn btn-success btn-sm"><i class="fa fa-paperclip"></i></button></td> <td><button data-target="" data-toggle="modal" title="duplicate" class="btn btn-success btn-sm"><i class="fa fa-copy"></i></button></td> </c:forEach> here is my whole code Commented Jun 6, 2018 at 2:11

1 Answer 1

1

Change your template for onClick to the following

<button onclick = "edit('${temp.id}')" data-target="#myModal1" data-toggle="modal" title="Edit" class="btn btn-success btn-sm"><i class="fa fa-edit"></i>Edit</button>

Make sure to have single quotes around '${temp.id}' so that javascript will treat it as a string literal.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't want that '${temp.id}' as string literal that is actal id int type
What do you get inside your onclick method as id after doing that change?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.