Hello,
Is it possible to get the value of this variable
${googleBreadcrumb}
accessible to javascript?
thanks for any help
Hello,
Is it possible to get the value of this variable
${googleBreadcrumb}
accessible to javascript?
thanks for any help
Hi
If you are looking for answer in one word, then thats No.
I guess you may have figured that(sigh) jsp is server side and javascript is client side…but if you submit the button(whatever), you can retrieve the selectedValue of the textbox/dropdown/whatever.
Hope this is what you are looking for.
try something like
<script>
var javascriptVariable = “${googleBreadcrumb}”;
alert( javascriptVariable ); //test the value
</script>
As long as googleBreadcrumb has a value, JSP will insert that value into the response (or an empty string, if no value) it’s creating, which happens before the javascript is parsed by the client.
What, I think, ajos777 is alluding to is the fact that the value must be submitted to the server at some point before JSP can insert it into the response.
This is very common task and rushiku’s solution is the most common one. Still, I recommend to do this on jsp tag lib. It’s essentially the same thing except, in the source of JSP, you won’t see the javascript directly and maybe reusable on other pages.
ajos777
Hope this is what you are looking for.
you didn’t say anything
rushiku
Thanks you for actually answering the question. It certainly leads me in the right direction. Funny that the simple answer was to put quotes around the jsp variable
sg707
Thanks for jumping in again with some useful info. I am not familiar with the jsp tag lib, but no better time than now. thanks for the tip.
sg707
Thanks for jumping in again with some useful info. I am not familiar with the jsp tag lib, but no better time than now. thanks for the tip.
I would generally go the tag way as well, but you can also do something like this:
<script type="text/javascript">
var javascriptVar = '<%= request.getParameter("someRequestParam") %>';
</script>
The only problem here, which will also be a problem with taglib is that it forces you to use inline javascript.