• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP & Javascript variables (passing one to other)

 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Assume I have a simple javascript function:
function foo(id) {
win = window.open();
win.document.write(id);
<% WorkGroup.setId(id???); %>
}
Basically, WorkGroup is a bean and I want to initialize its id variable with the javascript function parameter. I've passed JSP variables to javascript, however, I've heard that it cannot be done vice versa since JSP is translated previously to javascript? Is this true, and does anyone have any suggestion to accomplish this task?
Thanks everyone,
WS
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UPDATE
I'm currently trying to pass the variable via a hidden form field. But, perhaps someone may know a better way to solve this problem. I have:
1. an html table built dynamically with JSP
2. javascript event handlers to handle an onclick on a table cell
Now, what I want to do is when an onclick occurs in a given cell, initialize a bean with the value that is in that cell. Any ideas?
[ July 02, 2003: Message edited by: Winston Smith ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on whether you are doing a GET or POST you can have Javascript add variables to the URL or hidden form variables. Obviously this is a multistage process - you have to have a page on the user's browser that Javascript can execute in.
Bill
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are developing an app (not a website), you can also use a hidden iframe to pass data back & forth. -- OR -- you could use XMLHTTPRequest.
But if you are developing a web site, don't use these techniques; they might cause difficulty with some browsers.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you are developing a web site, don't use these techniques; they might cause difficulty with some browsers.

I use the hidden iframe technique often and without difficulty. If you are only concerned with reasonably modern browsers (in other words, not NN4) this is a viable technique.
hth,
bear
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill, Garrett, Bear. I've used the hidden form field and it's working smoothly. Once more, I appreciate all your help!
WS
[ July 03, 2003: Message edited by: Winston Smith ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!