Bookmark Topic Watch Topic
  • New Topic

Re:Assign jsp variable into javascript variable

 
Muthiah Raja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Report post to moderator
Change the code from

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

to

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

This will work
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic