• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing JSP variable to Javascript

 
Asger Asger
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have defined a value as
<c:set var="crid" value="${current.formattedReference}" />

this value of crid needs to be used in Javascript. I have the script as

<script type="text/javascript">
var str = "<%=${crid} %>";
alert(str);
var uri = 'http://xxxxxxxx/crid.do?item=' + str;
window.location(uri);
</script>


This doesnt work. Please help.

Thanks
A
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How doesn't it work? What happens if you run it? (Note that "window.location(xyz)" is not a meaningful expression in JavaScript.)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
Roberto Hernandez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JSTL instead of scriptlets
Try the following:
var str = "${crid}";

make sure JSTL taglib is declared before using it inside <script> tags
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!