% Soundcap cfl = new Soundcap();...">Geek Answers HandbookGetting jsp value in javascript fileI have the following code in abc.jsp:<%@page import="soundcap.Soundcap"%> <% Soundcap cfl = new Soundcap(); var sfl = cfl.playFile(); %> I need sfl value in external javascript file (jcode.js). How can I get this value (sfl) from jsp in javascript?+6javascript jspbdfios Apr 22 '13 at 19:03source share3 answersuse this ... <% //get your sfl %> <input type="hidden" id="sfl" value="<%=sfl%>"> in your js file use var sfl=document.getElementById("sfl").value; +1rahul maindargi Apr 22 '13 at 19:39source shareJust put your JSP value in the input tag as follows: <input type="hidden" id="value" value="${value}"> And get this value in JS as follows: var value = document.getElementById("value").value; +1zygimantus Apr 01 '15 at 8:23source shareVery simple: <% //get your sfl %> <script> var xyz = <% out.print(sfl); %>; </script> 011684 Apr 22 '13 at 19:10source shareMore articles:Avoid duplicate content for responsive page - htmlUIActivityViewController does not show Open in iBooks option - emailCentralize connection strings for multiple projects within the same solution - c #Guitolite - Remote: FATAL: Fingerprint failed for 'keydir /' - ruby-on-railsDoes LINQ return a deep copy of a collection? - c #SQL SELECT If (a = "") Then change the value of b - sqlUnable to replicate result using degree.distribution igraph - igraphHow to read a NAS assembly file. - assemblyd3js Redistributing labels around a pie chart - javascriptSplit the connection string between multiple web projects - c #All Articles
I have the following code in abc.jsp:
<%@page import="soundcap.Soundcap"%> <% Soundcap cfl = new Soundcap(); var sfl = cfl.playFile(); %>
I need sfl value in external javascript file (jcode.js). How can I get this value (sfl) from jsp in javascript?
use this ...
<% //get your sfl %> <input type="hidden" id="sfl" value="<%=sfl%>">
in your js file use
var sfl=document.getElementById("sfl").value;
Just put your JSP value in the input tag as follows:
<input type="hidden" id="value" value="${value}">
And get this value in JS as follows:
var value = document.getElementById("value").value;
Very simple:
<% //get your sfl %> <script> var xyz = <% out.print(sfl); %>; </script>