Oops, sorry... I thought you want to pass the value to other JSP. Weel, to
pass to a javascript, you need to make the JSP page to build the javascript
for you. Or better, just to have the JSP to build the attribute that holds
the value for you and the real JS process itself should be static. For
example:

in JSP:
<%
String myWords = "Hello girl".
out.println(" var myWords='" + myWords +"';");
%>

in JS:
function showMe()
{
  alert(myWords);
}

Hope this works
Rendra

-----Original Message-----
From: Celeste Haseltine [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 30, 2001 5:36 PM
To: [EMAIL PROTECTED]
Subject: How to pass a value from JSP code to JS code


I've run into a rode block that I hope someone can suggest a work around.  I
have an intranet site that the client wants custom menus for, where the menu
that is loaded is based off of the security level of the person logging in.
I obtain the menu string name that I want to load via my Login.jsp file.  I
then load my menu file via JavaScript code on the "Main" jsp page.  My
problem is that I can't remember how to simulate "passing" a parameter
obtained in my Login.jsp code into my JavaScript code on the Main.jsp page.
I am saving the value in a Java class for later retrieval via the Use Bean
tag.  I remember someone showing me how to do a work around for "passing
parameters" obtained from a JSP pages into JS on a following JSP page, and I
can't remember where I placed the sample code.  Does anyone remember how to
do this?  Thanks in advance for any advice/help.

Celeste


Login.jsp

//Read XML file
.......
//Now Search for User's Record
        outer:

        for (int i=0; i<nodeList.getLength(); i++)
        {
                org.w3c.dom.Node curNode = nodeList.item(i);

            //Get userID attribute:
            Element curElm = (Element)nodeList.item(i);
            String curUserID = curElm.getAttribute("userID");

            //Get pwd attribute:
            String curPwd = curElm.getAttribute("pwd");

            //Get menu attribute:
            String curMenu = curElm.getAttribute("menu");


            if (curUserID.equals(userID) && curPwd.equals(pwd))
            {
              routeURL = "Main.jsp";
 //now pass values to a Java class.  Will use this class in later JSP via
the USE BEAN tag.
              loggingon.setUserID(userID);
              loggingon.setSecure();
//Save the string in the variable "menu". Pass into my Javascript code for
the parameter MenuString.
              loggingon.setMenu(menu);
              break outer;
                } //end if
        }//end for

//Now Route to Main.jsp (i.e. routeURL = Main.jsp) if login is correct, if
not then route to Error.jsp.

<script
language="javascript">setTimeout("document.location='<%=routeURL%>'",100)</s
cript>


HM_Loader.js  (script is run when Main.jsp is loaded)

if(HM_IsMenu) {
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC=MenuString + ".js"
TYPE='text/javascript'><\/SCR" + "IPT>");
}

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to