Getting a value from scriptlet to javascript

By navnith

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.

Tags:

One Response to “Getting a value from scriptlet to javascript”

  1. Bookmarks about Javascript Says:

    [...] – bookmarked by 4 members originally found by zacefronISminemine on 2008-09-13 Getting a value from scriptlet to javascript http://navnith.wordpress.com/2008/07/16/getting-a-value-from-scriptlet-to-javascript/ – bookmarked [...]

Leave a Reply