• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

passing jsp variable to a javascript function

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup, that did it. Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic