Pass JSP Variable into JavaScript function

A

Anuradha Uduwage

Hi I have the following jsp page (I am only putting the area which is
relevant for this question) that use custom jsp tags. What I want to
do is change the window title based on the value that I get from the
properties file.

JSP File

<%@ include file="/netmarkets/jsp/util/beginPopup.jspf"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://someDotCome/windchill/taglib/components"
prefix="jca"%>
<%@ taglib uri="http://someDotCome/taglib/core" prefix="wc"%>
<%@ taglib uri="http://someDotCome/taglib/fmt" prefix="fmt"%>
....
....
<fmt:message var="tableLabel" key="<
%=partReportsRB.MULTI_LEVEL_BOM_LABEL%>" />

var tableLabel has the Window title that I want to appear in the
window title. So I created the following javascript to be added into
the above jspfile

<%-- Set window title based on rbinfo value --%>
<script language="javascript" type="text/javascript">
window.document.title = "${tableLabel}";
</script>

Above method works fine and it does what I want but, I want to make it
more developer friendly. Instead of adding this Javascript segment
into multiple jsp page I want to create a javascript file and include
that in the jsp file. But I want use the tableLabel variable. I am not
sure how I accomplish this.

I add above script into javascript function,

//Set Window title for the report based on the RbInfo data.
// do i need to add a path to the jsp file..?
function setWindowTitle() {
var rbinfoValue = document.getElementById("var");
window.document.title = rbinfoValue;
}

But I dont this is the correct.

Any help would be greatly appreciated.
Thanks,
Anuradha
 
D

dhtml

Anuradha said:
<%-- Set window title based on rbinfo value --%>
<script language="javascript" type="text/javascript">
window.document.title = "${tableLabel}";
</script>

Above method works fine and it does what I want but, I want to make it
more developer friendly. Instead of adding this Javascript segment
into multiple jsp page I want to create a javascript file and include
that in the jsp file. But I want use the tableLabel variable. I am not
sure how I accomplish this.

What is wrong with using include?

Did you try setting a variable?

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top