File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing jsp variable to a javascript function

 
Alex Kravets
Ranch Hand
Posts: 476
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have JSP page in which I pass a java value to a JavaScript function. A value is a name of a page passed to JavaScript window pop-up function. I get an error when I try to do it:
jsp page:
---------
String hlpFile = "test";
.
.
out.println("<a href=\"javascript:loadWin(" + hlpFile + ")\" class=\"nav\">" + prog + "-" + hlpFile + "</a>\n");

JavaScript function:
--------------------
function loadWin(file){
helpWin = window.open("generic_help/"+file,"help","height=650,width=800,resize=1,scrollbars=yes,top=10,left=100");
}
In browser's JavaScript "console" I get:
Error: 'test' is undefined
Any suggestions why this does not work?
thanks,
Alex
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

out.println("<a href=\"javascript:loadWin(" + hlpFile + ")\" class=\"nav\">" + prog + "-" + hlpFile + "</a>\n");

Try to add quotes around the hlpFile variable:
 
Alex Kravets
Ranch Hand
Posts: 476
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup, that did it. Thanks!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic