jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Intialize javascript variable using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Intialize javascript variable using jsp" Watch "Intialize javascript variable using jsp" New topic
Author

Intialize javascript variable using jsp

tony al
Greenhorn

Joined: Jul 03, 2002
Posts: 8
Hello,
I am experiencing the following problem in my JSP page which uses javascript;
I need to intialize a javascript variable as follows:
rootFld = F("class").I("1.1").I("1.2")._(F("1.3").I("1.3.1").I("1.3.2"))._(F("1.4").I("1.4.1"))._(F("1.5").I("1.5.2")) ;
This variable represents a dynamic tree structure that is to be displayed on the webpage.
I need to initialize the above variable from a variable in java scriptlet. As you can see the variable is not a string and I am not sure how to initiaze it using a java variable.
Any help is much appreciated
thanks
Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
In your jsp, set a String to the value you wish to assign to the javascript variable:
String jsVar = "whatever";
Then, set the javascript variable in the output:
Ronald Francis
Ranch Hand

Joined: Aug 02, 2001
Posts: 30
Watch out ...the double quotes in your example could cause some pain ..
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Please don't post teh same question in more than one forum. You obviously read more than one forum, so do the people who might answer your question.
There are more answers to this question in this other thread, but I have closed it and referred readers to this one.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Intialize javascript variable using jsp