It's not a secret anymore!
The moose likes JSP and the fly likes Please help me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Please help me." Watch "Please help me." New topic

Please help me.

Michael Zhang

Joined: Dec 03, 2002
Posts: 17
Hi, all.
I want to use JavaScript's variable in JSP block. I know JavaScript is Client-Side script and JSP is Server-Side script, so, following code is impossible, but I hope it's another way to achieve my aim. Please help me.
SCRIPT language=JavaScript>
function loadSubMenu(Value){
<% Vector term1 = teacher.getTerm(Value); //I want to use JavaScript's variable "Value"
xia zhi

Joined: Mar 27, 2003
Posts: 2
no way......
it's impossible.
Peter Daly

Joined: Jan 04, 2002
Posts: 17
Here is the flow of things:
JSP Run -> client receives page -> JavaScript Runs
JavaScript can never talk directly to JSP, since in a Page's life, JSP is "done" by the time JavaScript starts executing.
What you want to do may be possible, but not the way you are thinking about doing it. You could load the page again (controlled by JavaScript) passing the value of the JavaScript variable as a parameter on the request. For example "mypage.jsp?field=value".
We might be able to provide more help if we knew more (from and end user perspective) what you were trying to accomplish.
[ March 27, 2003: Message edited by: Peter Daly ]
Michael Zhang

Joined: Dec 03, 2002
Posts: 17
Thanks a lot.
Arron Zhang

Joined: Dec 27, 2002
Posts: 15
try this,
<form name="form1" action="">
<input type="hidden" name="a" value="">
<script language="javascript">
//set value of "a"
//set action of "form1"

novelist & programmer
I agree. Here's the link:
subject: Please help me.
jQuery in Action, 3rd edition