-2

Here is my code :

JSP :

String userId = rs.getString("user_id");

<center><a href="#"  onclick="edit(\'' + userId + '\');">Edit</a></center>

JavaScript :

 function edit(id)
 {
         alert(" user id is "+id);

 }

but it does not works.

it gives error :

Uncaught SyntaxError: Unexpected token ILLEGAL

Narm
  • 10,677
  • 5
  • 41
  • 54
Wild Eagle
  • 41
  • 1
  • 4
  • 1
    possible duplicate of [Reading a JSP variable from JavaScript](http://stackoverflow.com/questions/4803906/reading-a-jsp-variable-from-javascript) – Surya Nov 08 '14 at 10:41
  • 1
    Is this you've tried to code?? Nobody will understand what is the actual problem. Please post a code that everyone here can understand what is bugging over here – Vighanesh Gursale Nov 08 '14 at 10:41
  • Try this:
    Edit
    – Amy Nov 08 '14 at 10:43

2 Answers2

0

you need to do this

var userId = '${userId}'   <-- with ${} you get the var.

or:

... onclick="edit('userId')" ...


function edit(userId) {
    var id = rs.getString(userId);
    alert('id is: ' + id);
}

Best regards.

Arturo
  • 261
  • 1
  • 4
  • 19
-2

hey frinds use this code

<center><a href="#"  onclick="edit(  <%=userId %>  ;">Edit</a></center>
The Ray of Hope
  • 738
  • 1
  • 6
  • 16