It's not a secret anymore!*
The moose likes JSP and the fly likes Re:Assign jsp variable into javascript variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

Re:Assign jsp variable into javascript variable

Muthiah Raja
Greenhorn

Joined: Feb 06, 2005
Posts: 9
I am trying to assign JSP String variable to Javascript variable.
For that i use the follwing code

<% String str="Raja"; %>
var s=<%=str%>;
alert(s);

But this code is not worked.

Instead of writting var s=<%=str%>;

I try var s='<%=str%>';
I try var s="<%=str%>";

this code also not worked.

Kindly help me.
pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
Change the code from

<% String str="Raja"; %>
var s=<%=str%>;
alert(s);

to

<% String str="Raja"; %>
var s="<%=str%>";
alert(s);

This will work


Regards,
Pankaj Patil
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Muthina,
Please don't spread one conversation over more than one thread.
This is a continuation of:
http://www.coderanch.com/t/288527/JSP/java/Assign-Jsp-variable-Javascript-variable
I will respond there.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Re:Assign jsp variable into javascript variable
 
Similar Threads
get string values from Request and Session
Assign Jsp variable to Javascript variable
how can i put java script value into jsp variable?
tree like select list (html)
compare jsp variable and javascript variable