-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
  • 9,441
  • 5
  • 39
  • 52
Wild Eagle
  • 41
  • 1
  • 4

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
  • 700
  • 1
  • 6
  • 16