Forums Register Login

Re:Assign jsp variable into javascript variable

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Change the code from

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

to

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

This will work
+Pie Number of slices to send: Send
Muthina,
Please don't spread one conversation over more than one thread.
This is a continuation of:
https://coderanch.com/t/288527/JSP/java/Assign-Jsp-variable-Javascript-variable
I will respond there.
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


Reply locked
This thread has been viewed 1111 times.
Similar Threads
get string values from Request and Session
how can i put java script value into jsp variable?
tree like select list (html)
compare jsp variable and javascript variable
html output problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:09:12.