Getting a value from scriptlet to javascript

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.

Advertisements

Tags:

3 Responses 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 https://navnith.wordpress.com/2008/07/16/getting-a-value-from-scriptlet-to-javascript/ – bookmarked […]

  2. Eugene Says:

    Thanks! That’s works!

  3. palamaivirumbi Says:

    Thanks.
    It helped.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: