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> ??

1 Answer 1

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.

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

Comments

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.