JavaScript Pass JSP value to external Javascript file pass jsp value to external javascript file

Is there a way that I can pass a JSP variable value to an external Javascript file by using only Javascript and JSP. Something like:

JSP

String str = "Hello";

external.js

//not working
var str = "<%=str%>";

Thanks.

Answer:1

If you think that the java script is written inside the JSP then its possible.

But you are providing the JS file separately then you can make a global variable and that variable will be available everywhere.

Answer:2

Your not going to be able to write to the external js file. However if you put var s = "<%=str%>";in your jsp s will become a global variable which can be used within your external js file because s will have a global scope. So in a nutshell, you can't modify the actual js file, but you can add a variable with global scope and reference that variable within your external js script.

Answer:3

I defined a global Javascript function: function resizeDashBoardGridTable(gridID){ var table = document.getElementById('treegrid_'+gridID); ..... } After this function was used a few ...

I defined a global Javascript function: function resizeDashBoardGridTable(gridID){ var table = document.getElementById('treegrid_'+gridID); ..... } After this function was used a few ...

In Java regexes, you can use the intersection operator && in character classes to define them succinctly, e.g. [a-z&&[def]] // d, e, or f [a-z&&[^bc]] // a through z, ...

In Java regexes, you can use the intersection operator && in character classes to define them succinctly, e.g. [a-z&&[def]] // d, e, or f [a-z&&[^bc]] // a through z, ...

I'm trying to get the dropdown to change the textbox, but seem to be having issues. <head> <title>DropDown</title> <meta http-equiv="content-type" content="text/html;...

I'm trying to get the dropdown to change the textbox, but seem to be having issues. <head> <title>DropDown</title> <meta http-equiv="content-type" content="text/html;...

  1. html dropdownlist selected index changed event javascript
  2. dropdownlist selected index changed event in javascript