Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I am very impressed with the site and have already recommended it to one of my associates. I was truly impressed with the quickness in which someone actually responded to my question..."

Geography

Where in the world do Tek-Tips members come from?
pouet (Programmer)
10 May 01 9:27
Hello,

How can I assign the value of a JSP variable(which contains HTML tags) in a Javascript variable ?

I know that JS is for the client and JSP is server side but it may be possible to assign a Javascript variable once ...

I've tried this but it didn't work:

<%
  var myJSP = "<FONT FACE=\"Arial\">Testing...</FONT>";
%>
<SCRIPT language="JavaScript">
function overlap()
{
   document.all.mydiv.innerHTML = "<% =myJSP %>";
}

I also tried to use this:

<INPUT TYPE="HIDDEN" NAME="mytest" VALUE="<% =myJSP%>">

And then call in my JS function mytest.value but it only works with string but not HTML tags.

Can someone help me please????? I'm lost.....
scotth4v (Programmer)
16 May 01 15:47
well, I'd try assigning the form variables like you did, but instead of using the ">" and "<" (that break the tag) use "& gt;" and "& lt;" (remove spaces, I added them so you could see it here) that should keep it from breaking the form tag value attribute.

-Scott
CatWeasel (Programmer)
17 May 01 4:19
I think that the problem is that you use
<% =myJSP %> instead of
<%= myJSP %>.
The difference between those two is that the first JSP code is copied directly into the servlet that is generated and tries to perform the statement ' =myJSP'. The second statement prints the value of the variable to the page.

Hope this helps,
Steven.
mkm (TechnicalUser)
27 Jul 01 9:34
hi all,
how can i assign javascript variables to my jsp variables?

thanx in advance
mukesh
wushutwist (Programmer)
27 Jul 01 9:40
You pass the javascript variables over in a HTTP GET or POST request to the JSP.  The most common way is by setting the value of hidden HTML fields when the FORM is submitted.

On the JSP side you will have to get the parameters from the HttpServletRequest object.  This is easily done:

<%
String name = request.getParameter("name");
%>


Where name is the parameter you are passing.

Wushutwist

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close