• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing a variable from html/jsp to javascript  RSS feed

 
Satish Ray
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to pass a variable used in html/jsp to javascript. How can I do this?
please respond.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean something like this?

<%
String s = "test";
%>

<script>
alert('<%=s%>');
</script>
 
Satish Ray
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dawson,

Yeah I am looking out for the same functionality. But can we be albe to access the variable used in html/jsp inside javascript.

i tried with this earlier, but I am not getting the output. Are there any other options?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lynette Dawson:
<script>
alert('<%=s%>');
</script>


Use JSTL instead.

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satish Ray:
Yeah I am looking out for the same functionality. But can we be albe to access the variable used in html/jsp inside javascript.

i tried with this earlier, but I am not getting the output. Are there any other options?


JSP is a server-side technology whereas javascript runs on client-side. What are you trying to acheive? Please post your code snippet.
 
Satish Ray
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dawson,
Thanks its working.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!