Javascript runs on the client, JSP runs on the server. They cannot
communicate with each other directly. If you are advanced enough, look
into a servlet web service and AJAX to solve your problem, if it must
absolutely be dynamic. Otherwise, you are going to have to submit your form.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
If you mean passing a variable that only exists as a javascript variable,
you cannot. What you can do, however, is to provide a hidden input
field in your form, and write the value of the variable to this input field
before you submit your form.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
With a field as follows:
Then in Javascript you can do:
document.form.variableName.value="value";
form.submit();
and the JSP can evaluate the param "variableName". Remember though, that a Parameter is always a String (or an array of strings if accessed through a different method) so you will need a way to transform this string to what you want, if you want something other than a String (e.g. an Integer).
Bt to tell you the truth I am not sure what you by a null value in javascript. Don't forget that anything that the JSP reads from the params, must then turn around and insert the value back into the hidden field to be read by the javascript on the client (or actually modify the javascript in the JSP before returning the html to the client).
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
Your JavaScript in the above post is malformed. Look at the first function. It isn't ended until the } at the very end of the JavaScript section. That is probably why you are having problems.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494