Getting value from a scriptlet into javascript is pretty simple. However the otherway round which means getting a value from a scriptlets into javascript may not be too simple.
You could probably have a hidden parameter, have its
value = <%=request.getParameter(“value”) %>
and how this request parameter is going to get populated is, when you have the jsp submit the request to itself, i.e., have the action = to the same jsp page. For submitting the page to another action, you will have to write a submitForm()
method and have it populated with this.form.action=youraction
and then submit it.
Now on to the main topic, to get a value from scriptlet into javascript you could :
String a = “abc”;
Then make a hidden element in our good old HTML
<input type=”hidden” name=”testa” id=”testa” value=<%= a%> >
In the javascript where you want to fetch the value, you can do a
document.getElementById(“testa”).value;
thats all.
September 26, 2008 at 3:30 pm |
[…] – bookmarked by 4 members originally found by zacefronISminemine on 2008-09-13 Getting a value from scriptlet to javascript https://navnith.wordpress.com/2008/07/16/getting-a-value-from-scriptlet-to-javascript/ – bookmarked […]
February 27, 2011 at 9:27 am |
Thanks! That’s works!
July 12, 2011 at 10:17 am |
Thanks.
It helped.