0

Just wondering is it possible to call a java function from an onClick function in a table cell ?

Would it just be a simple <td onClick=<%=myFunction();%> temp </td> ??

user2908705
  • 19
  • 1
  • 5

1 Answers1

0
<td onClick="myFunction()"> temp </td>

Should work. If you use <% %> (I'm assuming this is a .jsp?) then it will want to run the Java function myFunction() in the current namespace on the server-side, not your Javascript function on the client side (which you need defined in a tag somewhere). Also with <% %>, even if that is a Java function that outputs code, it won't display here. You need <%= %> to display the output.

I think you might need to go back and ready up on the difference between client side Javascript and server side code execution. The question indicates you might not have a clear understanding between the two.

In your example, clicking on that link won't execute the function. That function will get executed before the page renders. If you want to have a call back, you need to implement AJAX. I recommend looking at libraries like jQuery to implement this.

djsumdog
  • 2,560
  • 1
  • 29
  • 55