How to read a user defined java method inside a javascript
I have a scenario where I have a form with 2 fields and a submit button. On clicking submit button, I call a javascript which needs to call a user-defined method.
Please provide solution to do this and also please provide any useful links that i can go follow.
Thanks
[287 byte] By [
snehaka] at [2007-11-27 11:44:50]

# 1
mix scriptlet inside js fn.
function getVal() {
var getValue;
<% MyBO abc = new MyBO;
String value = abc.<call your java method here>;
%>
getValue = '<%= value %>';
}
OR
you can use AJAX, the callback fn will get the value from the server side.
skp71a at 2007-7-29 17:58:11 >

# 2
Java != javascript.
You can not call java directly from javascript.
The lifecycle:
Request received
Java/JSP runs produces an HTML page
Java stops running
Javascript runs on page when page is loaded.
The only way to call java code again is to submit a request and get the result back in a response. Traditionally the response is a new JSP page to replace the old one.
Using AJAX the response can be just information that you then alter the current page with.
The first example given by skp71 will probably NOT be what you are after. The java code is executed when you load the page, NOT when you push the button which is most probably what you are after.
AJAX is a solution, as is loading a new page.
Cheers,
evnafets