• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

passing a variable from html/jsp to javascript

 
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.
 
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?
 
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.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!